Skip to content

Commit

Permalink
Merge pull request #5 from Zenify/refresh
Browse files Browse the repository at this point in the history
bump to PHP 7, use local phpunit, cleanup, improve README, make travi…
  • Loading branch information
Tomáš Votruba committed Nov 1, 2016
2 parents 5faa5f5 + 392c209 commit fbdcb50
Show file tree
Hide file tree
Showing 25 changed files with 147 additions and 205 deletions.
15 changes: 2 additions & 13 deletions .scrutinizer.yml
@@ -1,17 +1,6 @@
before_commands:
- "composer install --prefer-source"

tools:
external_code_coverage:
timeout: 900
sensiolabs_security_checker: true
php_code_coverage:
enabled: true
php_analyzer:
config:
verify_php_doc_comments:
suggest_more_specific_types: false
external_code_coverage: true

checks:
php:
code_rating: true
code_rating: true
29 changes: 17 additions & 12 deletions .travis.yml
@@ -1,22 +1,27 @@
language: php

sudo: false

php:
- 5.6
- 7.0
- hhvm
- 7.1

matrix:
include:
- php: 7.0
env: PHPUNIT_FLAGS="--coverage-clover coverage.xml" CHECK_CS=true

install:
- composer create-project --prefer-source --dev --no-interaction zenify/ci vendor/ci @dev
- . vendor/ci/travis/coverage-init.sh
# install composer dependencies
- composer install --prefer-source

before_script:
- . vendor/ci/travis/static-analysis.sh

script:
- phpunit $PHPUNIT_FLAGS
# run tests
- vendor/bin/phpunit $PHPUNIT_FLAGS
# check coding standard (defined in composer.json "scripts" section)
- if [[ "$CHECK_CS" != "" ]]; then composer check-cs; fi

after_script:
- . vendor/ci/travis/coverage-send.sh
# upload coverage.xml file to Scrutinizer to analyze it
- |
if [[ "$PHPUNIT_FLAGS" != "" ]]; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.xml
fi
37 changes: 24 additions & 13 deletions README.md
Expand Up @@ -44,10 +44,7 @@ use Zenify\DoctrineFilters\Contract\FilterInterface;
final class SoftdeletableFilter implements FilterInterface
{

/**
* {@inheritdoc}
*/
public function addFilterConstraint(ClassMetadata $entity, $alias)
public function addFilterConstraint(ClassMetadata $entity, string $alias) : string
{
if ($entity->getReflectionClass()->hasProperty('isDeleted')) {
return "$alias.isDeleted = 0");
Expand All @@ -61,9 +58,9 @@ final class SoftdeletableFilter implements FilterInterface

Then register as service:

`config.neon`

```yaml
# app/config/config.neon
services:
- SoftdeletableFilter
```
Expand Down Expand Up @@ -99,19 +96,13 @@ final class SoftdeletableFilter implements ConditionalFilterInterface
}


/**
* {@inheritdoc}
*/
public function addFilterConstraint(ClassMetadata $entity, $alias)
public function addFilterConstraint(ClassMetadata $entity, string $alias) : string
{
// same as above
}


/**
* {@inheritdoc}
*/
public function isEnabled()
public function isEnabled() : bool
{
if ($this->user->isLoggedIn() && $this->user->hasRole('admin')) {
return FALSE;
Expand All @@ -123,3 +114,23 @@ final class SoftdeletableFilter implements ConditionalFilterInterface
```

Voilá!



## Testing

```sh
composer check-cs
vendor/bin/phpunit
```


## Contributing

Rules are simple:

- new feature needs tests
- all tests must pass
- 1 feature per PR

We would be happy to merge your feature then!
20 changes: 12 additions & 8 deletions composer.json
@@ -1,22 +1,23 @@
{
"name": "zenify/doctrine-filters",
"type": "nette-extension",
"description": "Doctrine Filters integration into Nette",
"license": "MIT",
"authors": [
{ "name": "Tomáš Votruba", "homepage": "http://tomasvotruba.cz" }
],
"require": {
"php": ">=5.6",
"doctrine/orm": "~2.4",
"nette/application": "~2.3",
"nette/di": "~2.3",
"php": "^7.0",
"doctrine/orm": "~2.5",
"nette/application": "~2.4",
"nette/di": "~2.4",
"symnedi/event-dispatcher": "~0.2"
},
"require-dev": {
"kdyby/doctrine": "~3.0",
"nette/bootstrap": "~2.3",
"tracy/tracy": "~2.3"
"kdyby/doctrine": "~3.1",
"nette/bootstrap": "~2.4",
"tracy/tracy": "~2.4",
"phpunit/phpunit": "^5.6",
"zenify/coding-standard": "^4.0"
},
"autoload": {
"psr-4": {
Expand All @@ -27,5 +28,8 @@
"psr-4": {
"Zenify\\DoctrineFilters\\Tests\\": "tests"
}
},
"scripts": {
"check-cs": "vendor/bin/phpcs src tests -ps --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/ruleset.xml"
}
}
8 changes: 1 addition & 7 deletions phpunit.xml
@@ -1,11 +1,6 @@
<phpunit
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
colors="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertErrorsToExceptions="true"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite>
Expand All @@ -18,4 +13,3 @@
</whitelist>
</filter>
</phpunit>

8 changes: 4 additions & 4 deletions src/Contract/ConditionalFilterInterface.php
@@ -1,6 +1,8 @@
<?php

/**
declare(strict_types=1);

/*
* This file is part of Zenify
* Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
*/
Expand All @@ -14,9 +16,7 @@ interface ConditionalFilterInterface extends FilterInterface
/**
* Resolves conditions that are required to enable filter.
* Filters are active by default.
*
* @return bool
*/
function isEnabled();
public function isEnabled() : bool;

}
29 changes: 0 additions & 29 deletions src/Contract/DI/DefinitionFinderInterface.php

This file was deleted.

11 changes: 4 additions & 7 deletions src/Contract/FilterInterface.php
@@ -1,6 +1,8 @@
<?php

/**
declare(strict_types=1);

/*
* This file is part of Zenify
* Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
*/
Expand All @@ -13,11 +15,6 @@
interface FilterInterface
{

/**
* @param ClassMetadata $targetEntity
* @param string $targetTableAlias
* @return string
*/
function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias);
public function addFilterConstraint(ClassMetadata $targetEntity, string $targetTableAlias) : string;

}
12 changes: 5 additions & 7 deletions src/Contract/FilterManagerInterface.php
@@ -1,6 +1,8 @@
<?php

/**
declare(strict_types=1);

/*
* This file is part of Zenify
* Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
*/
Expand All @@ -11,16 +13,12 @@
interface FilterManagerInterface
{

/**
* @param string $name
* @param FilterInterface $filter
*/
function addFilter($name, FilterInterface $filter);
public function addFilter(string $name, FilterInterface $filter);


/**
* Enables all filters that meet its conditions.
*/
function enableFilters();
public function enableFilters();

}
18 changes: 7 additions & 11 deletions src/DI/DefinitionFinder.php
@@ -1,18 +1,20 @@
<?php

/**
declare(strict_types=1);

/*
* This file is part of Zenify
* Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
*/

namespace Zenify\DoctrineFilters\DI;

use Nette\DI\ContainerBuilder;
use Zenify\DoctrineFilters\Contract\DI\DefinitionFinderInterface;
use Nette\DI\ServiceDefinition;
use Zenify\DoctrineFilters\Exception\DefinitionForTypeNotFoundException;


final class DefinitionFinder implements DefinitionFinderInterface
final class DefinitionFinder
{

/**
Expand All @@ -27,10 +29,7 @@ public function __construct(ContainerBuilder $containerBuilder)
}


/**
* {@inheritdoc}
*/
public function getDefinitionByType($type)
public function getDefinitionByType(string $type) : ServiceDefinition
{
$this->containerBuilder->prepareClassList();

Expand All @@ -48,10 +47,7 @@ public function getDefinitionByType($type)
}


/**
* {@inheritdoc}
*/
public function getServiceNameByType($type)
public function getServiceNameByType(string $type) : string
{
$this->containerBuilder->prepareClassList();

Expand Down
13 changes: 4 additions & 9 deletions src/DI/FiltersExtension.php
@@ -1,6 +1,8 @@
<?php

/**
declare(strict_types=1);

/*
* This file is part of Zenify
* Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
*/
Expand All @@ -9,7 +11,6 @@

use Doctrine\ORM\Configuration;
use Nette\DI\CompilerExtension;
use Zenify\DoctrineFilters\Contract\DI\DefinitionFinderInterface;
use Zenify\DoctrineFilters\Contract\FilterInterface;
use Zenify\DoctrineFilters\Contract\FilterManagerInterface;
use Zenify\DoctrineFilters\EventSubscriber\EnableFiltersSubscriber;
Expand All @@ -19,14 +20,11 @@ final class FiltersExtension extends CompilerExtension
{

/**
* @var DefinitionFinderInterface
* @var DefinitionFinder
*/
private $definitionFinder;


/**
* {@inheritdoc}
*/
public function loadConfiguration()
{
$containerBuilder = $this->getContainerBuilder();
Expand All @@ -37,9 +35,6 @@ public function loadConfiguration()
}


/**
* {@inheritdoc}
*/
public function beforeCompile()
{
$containerBuilder = $this->getContainerBuilder();
Expand Down

0 comments on commit fbdcb50

Please sign in to comment.