This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
743 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
filter: | ||
excluded_paths: [vendor/*] | ||
|
||
checks: | ||
php: | ||
verify_property_names: true | ||
verify_access_scope_valid: true | ||
variable_existence: true | ||
useless_calls: true | ||
use_statement_alias_conflict: true | ||
use_self_instead_of_fqcn: true | ||
uppercase_constants: true | ||
unused_variables: true | ||
unused_properties: true | ||
unused_parameters: true | ||
unused_methods: true | ||
unreachable_code: true | ||
too_many_arguments: true | ||
symfony_request_injection: true | ||
switch_fallthrough_commented: false | ||
sql_injection_vulnerabilities: true | ||
single_namespace_per_use: true | ||
simplify_boolean_return: true | ||
side_effects_or_types: true | ||
security_vulnerabilities: true | ||
return_doc_comments: true | ||
return_doc_comment_if_not_inferrable: true | ||
require_scope_for_properties: true | ||
require_scope_for_methods: true | ||
require_php_tag_first: true | ||
psr2_switch_declaration: true | ||
psr2_class_declaration: true | ||
properties_in_camelcaps: true | ||
precedence_mistakes: true | ||
precedence_in_conditions: true | ||
phpunit_assertions: true | ||
php5_style_constructor: true | ||
parse_doc_comments: true | ||
parameters_in_camelcaps: true | ||
parameter_non_unique: true | ||
parameter_doc_comments: true | ||
param_doc_comment_if_not_inferrable: true | ||
overriding_private_members: true | ||
optional_parameters_at_the_end: true | ||
one_class_per_file: true | ||
no_unnecessary_if: true | ||
no_unnecessary_final_modifier: true | ||
no_underscore_prefix_in_properties: true | ||
no_underscore_prefix_in_methods: true | ||
no_trailing_whitespace: true | ||
no_short_variable_names: | ||
minimum: '2' | ||
no_short_open_tag: true | ||
no_short_method_names: | ||
minimum: '3' | ||
no_property_on_interface: true | ||
no_non_implemented_abstract_methods: true | ||
no_goto: true | ||
no_global_keyword: true | ||
no_exit: true | ||
no_eval: true | ||
no_error_suppression: true | ||
no_empty_statements: true | ||
no_commented_out_code: true | ||
no_debug_code: true | ||
no_duplicate_arguments: true | ||
newline_at_end_of_file: true | ||
argument_type_checks: true | ||
assignment_of_null_return: true | ||
avoid_aliased_php_functions: true | ||
avoid_closing_tag: true | ||
avoid_conflicting_incrementers: true | ||
avoid_duplicate_types: true | ||
avoid_multiple_statements_on_same_line: true | ||
avoid_superglobals: true | ||
fix_doc_comments: true | ||
non_commented_empty_catch_block: false | ||
line_length: | ||
max_length: '120' | ||
encourage_single_quotes: true | ||
classes_in_camel_caps: true | ||
more_specific_types_in_doc_comments: true | ||
avoid_unnecessary_concatenation: true | ||
remove_extra_empty_lines: true | ||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: false | ||
order_alphabetically: false | ||
fix_line_ending: true | ||
function_in_camel_caps: true | ||
|
||
tools: | ||
external_code_coverage: true | ||
php_code_sniffer: | ||
config: | ||
standard: "PSR2" | ||
|
||
build_failure_conditions: | ||
- 'patches.new.exists' # No patches allowed | ||
- 'issues.label("coding-style").new.exists' # No coding style issues allowed | ||
- 'issues.label("documentation").new.exists' # No documentation issues allowed | ||
- 'project.metric("scrutinizer.test_coverage", < 0.60)' # Code Coverage drops below 60% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: php | ||
php: | ||
- '5.6' | ||
- '7.0' | ||
|
||
env: | ||
- SYMFONY_VERSION=2.3.* | ||
- SYMFONY_VERSION=2.7.* | ||
- SYMFONY_VERSION=2.8.* | ||
- SYMFONY_VERSION=3.0.* | ||
- SYMFONY_VERSION=3.1.* | ||
|
||
before_script: | ||
- composer self-update | ||
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update | ||
- composer install --no-interaction | ||
|
||
script: | ||
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover | ||
|
||
after_success: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.SILENT: | ||
.PHONY: help | ||
|
||
## Colors | ||
COLOR_RESET = \033[0m | ||
COLOR_INFO = \033[32m | ||
COLOR_COMMENT = \033[33m | ||
|
||
## Help | ||
help: | ||
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n" | ||
printf " make <target>\n\n" | ||
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n" | ||
awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \ | ||
helpMessage = match(lastLine, /^## (.*)/); \ | ||
if (helpMessage) { \ | ||
helpCommand = substr($$1, 0, index($$1, ":")); \ | ||
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | ||
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \ | ||
} \ | ||
} \ | ||
{ lastLine = $$0 }' $(MAKEFILE_LIST) | ||
|
||
## Install | ||
install: | ||
composer install | ||
|
||
## Run tests | ||
test: | ||
vendor/bin/phpunit | ||
|
||
## Loop unit tests | ||
test-loop: | ||
while true; \ | ||
do vendor/bin/phpunit; \ | ||
read continue; \ | ||
done; | ||
|
||
## Code coverage | ||
coverage: | ||
vendor/bin/phpunit --coverage-text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,163 @@ | ||
# algolia-specification-bundle | ||
This bundle integrates algolia-specification with Symfony | ||
# Algolia specification bundle | ||
|
||
This bundle integrates [algolia-specification](git@github.com:gbprod/algolia-specification.git) with Symfony. | ||
|
||
![stability-wip](https://img.shields.io/badge/stability-work_in_progress-lightgrey.svg) | ||
|
||
[![Build Status](https://travis-ci.org/gbprod/algolia-specification-bundle.svg?branch=master)](https://travis-ci.org/gbprod/algolia-specification-bundle) | ||
[![codecov](https://codecov.io/gh/gbprod/algolia-specification-bundle/branch/master/graph/badge.svg)](https://codecov.io/gh/gbprod/algolia-specification-bundle) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gbprod/algolia-specification-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/gbprod/algolia-specification-bundle/?branch=master) | ||
[![Dependency Status](https://www.versioneye.com/user/projects/574a9c9ace8d0e004130d337/badge.svg)](https://www.versioneye.com/user/projects/574a9c9ace8d0e004130d337) | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/gbprod/algolia-specification-bundle/v/stable)](https://packagist.org/packages/gbprod/algolia-specification) | ||
[![Total Downloads](https://poser.pugx.org/gbprod/algolia-specification-bundle/downloads)](https://packagist.org/packages/gbprod/algolia-specification) | ||
[![Latest Unstable Version](https://poser.pugx.org/gbprod/algolia-specification-bundle/v/unstable)](https://packagist.org/packages/gbprod/algolia-specification) | ||
[![License](https://poser.pugx.org/gbprod/algolia-specification-bundle/license)](https://packagist.org/packages/gbprod/algolia-specification) | ||
|
||
## Installation | ||
|
||
Download bundle using [composer](https://getcomposer.org/) : | ||
|
||
```bash | ||
composer require gbprod/algolia-specification-bundle | ||
``` | ||
|
||
Declare in your `app/AppKernel.php` file: | ||
|
||
```php | ||
<?php | ||
// app/AppKernel.php | ||
|
||
public function registerBundles() | ||
{ | ||
$bundles = array( | ||
// ... | ||
new GBProd\AlgoliaSpecificationBundle\AlgoliaSpecificationBundle(), | ||
// ... | ||
); | ||
} | ||
``` | ||
|
||
## Create your specification and your query factory | ||
|
||
Take a look to [Specification](https://github.com/gbprod/specification) and [Algolia Specification](https://github.com/gbprod/specification) libraries for more informations. | ||
|
||
### Create a specification | ||
|
||
```php | ||
<?php | ||
|
||
namespace GBProd\Acme\CoreDomain\Specification\Product; | ||
|
||
use GBProd\Specification\Specification; | ||
|
||
class IsAvailable implements Specification | ||
{ | ||
public function isSatisfiedBy($candidate) | ||
{ | ||
return $candidate->isSellable() | ||
&& $candidate->expirationDate() > new \DateTime('now') | ||
; | ||
} | ||
} | ||
``` | ||
|
||
### Create a query factory | ||
|
||
```php | ||
<?php | ||
|
||
namespace GBProd\Acme\Infrastructure\Algolia\QueryFactory\Product; | ||
|
||
use GBProd\AlgoliaSpecification\QueryFactory\Factory; | ||
use GBProd\Specification\Specification; | ||
use Algolia\QueryBuilder; | ||
|
||
class IsAvailableFactory implements Factory | ||
{ | ||
public function build(Specification $spec, QueryBuilder $qb) | ||
{ | ||
return $qb->query()->bool() | ||
->addMust() | ||
$qb->query()->term(['available' => "0"]), | ||
) | ||
; | ||
} | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
### Declare your Factory | ||
|
||
```yaml | ||
// src/GBProd/Acme/AcmeBundle/Resource/config/service.yml | ||
|
||
services: | ||
acme.algolia.query_factory.is_available: | ||
class: GBProd\Acme\Infrastructure\Algolia\QueryFactory\Product\IsAvailableFactory | ||
tags: | ||
- { name: algolia.query_factory, specification: GBProd\Acme\CoreDomain\Specification\Product\IsAvailable } | ||
``` | ||
|
||
### Inject handler in your repository class | ||
|
||
```yaml | ||
// src/GBProd/Acme/AcmeBundle/Resource/config/service.yml | ||
|
||
services: | ||
acme.product_repository: | ||
class: GBProd\Acme\Infrastructure\Product\AlgoliaProductRepository | ||
arguments: | ||
- "@algolia.client" | ||
- "@gbprod.algolia_specification_handler" | ||
``` | ||
|
||
```php | ||
<?php | ||
|
||
namespace GBProd\Acme\Infrastructure\Product; | ||
|
||
use Algolia\Client; | ||
use Algolia\QueryBuilder; | ||
use GBProd\AlgoliaSpecification\Handler; | ||
use GBProd\Specification\Specification; | ||
|
||
class AlgoliaProductRepository implements ProductRepository | ||
{ | ||
private $client; | ||
|
||
private $handler; | ||
|
||
public function __construct(Client $em, Handler $handler) | ||
{ | ||
$this->client = $client; | ||
$this->handler = $handler; | ||
} | ||
|
||
public function findSatisfying(Specification $specification) | ||
{ | ||
$type = $this | ||
->getIndex('catalog') | ||
->getType('product') | ||
; | ||
|
||
$query = $this->handler->handle($specification, new QueryBuilder()); | ||
|
||
return $type->search($query); | ||
} | ||
} | ||
``` | ||
|
||
### Usage | ||
|
||
```php | ||
<?php | ||
|
||
$products = $productRepository->findSatisfying( | ||
new AndX( | ||
new IsAvailable(), | ||
new IsLowStock() | ||
) | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "gbprod/algolia-specification-bundle", | ||
"description": "This bundle integrates algolia-specification with Symfony", | ||
"type": "bundle", | ||
"require": { | ||
"php": ">=5.6", | ||
"gbprod/algolia-specification": "^0.1", | ||
"symfony/framework-bundle": "^2.3|^3.0", | ||
"symfony/expression-language": "^2.3|^3.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.5" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Gilles", | ||
"email": "contact@gb-prod.fr" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"autoload": { | ||
"psr-4": { | ||
"GBProd\\": "src/", | ||
"Tests\\GBProd\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.