-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted Linter from memio/validator 1.0.0-rc1
- Loading branch information
Loïc Chardonnet
committed
Apr 20, 2015
0 parents
commit 5304e09
Showing
31 changed files
with
1,201 additions
and
0 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,6 @@ | ||
# Third party | ||
/composer.lock | ||
/phpunit.xml | ||
/vendor | ||
/.couscous | ||
/.puli |
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,32 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
matrix: | ||
# include: | ||
# - php: 5.3.3 | ||
# env: COMPOSER_FLAGS="--prefer-lowest" | ||
allow_failures: | ||
- php: hhvm | ||
- php: 7.0 | ||
|
||
before_script: | ||
- curl http://cs.sensiolabs.org/get/php-cs-fixer.phar -o php-cs-fixer.phar | ||
- composer selfupdate | ||
- composer update $COMPOSER_FLAGS | ||
|
||
script: | ||
- echo '[phpspec] Running specification tests'; ./vendor/bin/phpspec run -n -f dot | ||
- output=$(php -n php-cs-fixer.phar fix -v --dry-run --config=sf23 .); if [[ $(grep -o F <<< $output | wc -l) -gt 3 ]]; then while read -r line; do echo -e "\e[00;31m$line\e[00m"; done <<< "$output"; false; fi; |
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,5 @@ | ||
# CHANGELOG | ||
|
||
## 1.0.0: Import | ||
|
||
* imported constraints from [memio/validator](http://github.com/memio/validator) v1.0.0-rc1 |
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,63 @@ | ||
# How to contribute | ||
|
||
Everybody should be able to help. Here's how you can make this project more | ||
awesome: | ||
|
||
1. [Fork it](https://github.com/memio/linter/fork_select) | ||
2. improve it | ||
3. submit a [pull request](https://help.github.com/articles/creating-a-pull-request) | ||
|
||
Your work will then be reviewed as soon as possible (suggestions about some | ||
changes, improvements or alternatives may be given). | ||
|
||
Here's some tips to make you the best contributor ever: | ||
|
||
* [Standard code](#standard-code) | ||
* [Specifications](#specifications) | ||
* [Keeping your fork up-to-date](#keeping-your-fork-up-to-date) | ||
|
||
## Standard code | ||
|
||
Use [PHP CS fixer](http://cs.sensiolabs.org/) to make your code compliant with | ||
Memio Linter's coding standards: | ||
|
||
./vendor/bin/php-cs-fixer fix --config=sf23 . | ||
|
||
## Specifications | ||
|
||
Memio Linter drives its development using [phpspec](http://www.phpspec.net/): | ||
|
||
# Generate the specification class: | ||
phpspec describe 'Memio\Validator\MyNewClass' | ||
|
||
# Customize the specification class: | ||
$EDITOR spec/Memio/Linter/MyNewClass.php | ||
|
||
# Generate the specified class: | ||
phpspec run | ||
|
||
# Customize the class: | ||
$EDITOR src/Memio/Linter/MyNewClass.php | ||
|
||
phpspec run # Should be green! | ||
|
||
## Keeping your fork up-to-date | ||
|
||
To keep your fork up-to-date, you should track the upstream (original) one | ||
using the following command: | ||
|
||
git remote add upstream https://github.com/memio/linter.git | ||
|
||
Then get the upstream changes: | ||
|
||
git checkout master | ||
git pull --rebase origin master | ||
git pull --rebase upstream master | ||
git checkout <your-branch> | ||
git rebase master | ||
|
||
Finally, publish your changes: | ||
|
||
git push -f origin <your-branch> | ||
|
||
Your pull request will be automatically updated. |
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,19 @@ | ||
Copyright (c) 2015 Loïc Chardonnet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,102 @@ | ||
# Memio's Linter [![Travis CI](https://travis-ci.org/memio/linter.png)](https://travis-ci.org/memio/linter) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/e5794d5b-5305-4569-bc9b-caeecf9ae982/mini.png)](https://insight.sensiolabs.com/projects/e5794d5b-5305-4569-bc9b-caeecf9ae982) | ||
|
||
A set of [Memio constraints](http://github.com/memio/validator) that check | ||
[Memio models](http://github.com/memio/model) for syntax errors and the likes. | ||
|
||
> **Note**: This package is part of [Memio](http://memio.github.io/memio), a highly opinionated PHP code generator. | ||
> Have a look at [the main repository](http://github.com/memio/memio). | ||
## Installation | ||
|
||
Install it using [Composer](https://getcomposer.org/download): | ||
|
||
composer require memio/linter:~1.0 | ||
|
||
## Example | ||
|
||
Usually we'd have to install [Memio](http://github.com/memio/memio) and use its | ||
`Build::linter()` method to get a linter validator. | ||
|
||
The atlernative would be to build manually the validator as follow: | ||
|
||
```php | ||
<?php | ||
|
||
require __DIR__.'/vendor/autoload.php'; | ||
|
||
use Memio\Validator\Constraint\ArgumentCannotBeScalar; | ||
use Memio\Validator\Constraint\CollectionCannotHaveNameDuplicates; | ||
use Memio\Validator\Constraint\ConcreteObjectMethodsCannotBeAbstract; | ||
use Memio\Validator\Constraint\ContractMethodsCanOnlyBePublic; | ||
use Memio\Validator\Constraint\ContractMethodsCannotBeFinal; | ||
use Memio\Validator\Constraint\ContractMethodsCannotBeStatic; | ||
use Memio\Validator\Constraint\ContractMethodsCannotHaveBody; | ||
use Memio\Validator\Constraint\MethodCannotBeAbstractAndHaveBody; | ||
use Memio\Validator\Constraint\MethodCannotBeBothAbstractAndFinal; | ||
use Memio\Validator\Constraint\MethodCannotBeBothAbstractAndPrivate; | ||
use Memio\Validator\Constraint\MethodCannotBeBothAbstractAndStatic; | ||
use Memio\Validator\Constraint\ObjectArgumentCanOnlyDefaultToNull; | ||
use Memio\Validator\ModelValidator\ArgumentValidator; | ||
use Memio\Validator\ModelValidator\CollectionValidator; | ||
use Memio\Validator\ModelValidator\MethodValidator; | ||
use Memio\Validator\ModelValidator\ContractValidator; | ||
use Memio\Validator\ModelValidator\ObjectValidator; | ||
use Memio\Validator\ModelValidator\FileValidator; | ||
use Memio\Validator\Validator; | ||
|
||
$argumentValidator = new ArgumentValidator(); | ||
$argumentValidator->add(new ArgumentCannotBeScalar()); | ||
|
||
$collectionValidator = new CollectionValidator(); | ||
$collectionValidator->add(new CollectionCannotHaveNameDuplicates()); | ||
|
||
$methodValidator = new MethodValidator($argumentValidator, $collectionValidator); | ||
$methodValidator->add(new MethodCannotBeAbstractAndHaveBody()); | ||
$methodValidator->add(new MethodCannotBeBothAbstractAndFinal()); | ||
$methodValidator->add(new MethodCannotBeBothAbstractAndPrivate()); | ||
$methodValidator->add(new MethodCannotBeBothAbstractAndStatic()); | ||
|
||
$contractValidator = new ContractValidator($collectionValidator, $methodValidator); | ||
$contractValidator->add(new ContractMethodsCanOnlyBePublic()); | ||
$contractValidator->add(new ContractMethodsCannotBeFinal()); | ||
$contractValidator->add(new ContractMethodsCannotBeStatic()); | ||
$contractValidator->add(new ContractMethodsCannotHaveBody()); | ||
|
||
$objectValidator = new ObjectValidator($collectionValidator, $methodValidator); | ||
$objectValidator->add(new ConcreteObjectMethodsCannotBeAbstract()); | ||
$objectValidator->add(new ObjectArgumentCanOnlyDefaultToNull()); | ||
|
||
$fileValidator = new FileValidator($contractValidator, $objectValidator); | ||
|
||
$linter = new Validator(); | ||
$linter->add($argumentValidator); | ||
$linter->add($collectionValidator); | ||
$linter->add($methodValidator); | ||
$linter->add($contractValidator); | ||
$linter->add($objectValidator); | ||
$linter->add($fileValidator); | ||
|
||
$linter->validator($anyModels); | ||
``` | ||
|
||
Have a look at [the main respository](http://github.com/memio/memio) to discover the full power of Medio. | ||
|
||
## Want to know more? | ||
|
||
Memio uses [phpspec](http://phpspec.net/), which means the tests also provide the documentation. | ||
Not convinced? Then clone this repository and run the following commands: | ||
|
||
composer install | ||
./vendor/bin/phpspec run -n -f pretty | ||
|
||
You can see the current and past versions using one of the following: | ||
|
||
* the `git tag` command | ||
* the [releases page on Github](https://github.com/memio/memio/releases) | ||
* the file listing the [changes between versions](CHANGELOG.md) | ||
|
||
And finally some meta documentation: | ||
|
||
* [copyright and MIT license](LICENSE) | ||
* [versioning and branching models](VERSIONING.md) | ||
* [contribution instructions](CONTRIBUTING.md) |
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,27 @@ | ||
# Versioning and branching models | ||
|
||
This file explains the versioning and branching models of this project. | ||
|
||
## Versioning | ||
|
||
The versioning is inspired by [Semantic Versioning](http://semver.org/): | ||
|
||
> Given a version number MAJOR.MINOR.PATCH, increment the: | ||
> | ||
> 1. MAJOR version when you make incompatible API changes | ||
> 2. MINOR version when you add functionality in a backwards-compatible manner | ||
> 3. PATCH version when you make backwards-compatible bug fixes | ||
### Public API | ||
|
||
Classes and methods marked with the `@api` tag are considered to be the public | ||
API of this project. | ||
|
||
## Branching Model | ||
|
||
The branching is inspired by [@jbenet](https://github.com/jbenet) | ||
[simple git branching model](https://gist.github.com/jbenet/ee6c9ac48068889b0912): | ||
|
||
> 1. `master` must always be deployable. | ||
> 2. **all changes** are made through feature branches (pull-request + merge) | ||
> 3. rebase to avoid/resolve conflicts; merge in to `master` |
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,29 @@ | ||
{ | ||
"name": "memio/linter", | ||
"license": "MIT", | ||
"type": "library", | ||
"description": "Memio's linter, a set of constraint that check models for syntax errors", | ||
"keywords": ["generator", "PHP", "code"], | ||
"homepage": "http://memio.github.io/memio", | ||
"authors": [ | ||
{ | ||
"name": "Loïc Chardonnet", | ||
"email": "[email protected]", | ||
"homepage": "http://gnugat.github.io", | ||
"role": "Developer" | ||
} | ||
], | ||
"autoload": { "psr-4": { | ||
"Memio\\Linter\\": "src/Memio/Linter" | ||
}}, | ||
"require": { | ||
"php": ">=5.3.3", | ||
"memio/model": "~1.0", | ||
"memio/validator": "~1.0" | ||
}, | ||
"require-dev": { | ||
"ciaranmcnulty/phpspec-typehintedmethods": "~1.1", | ||
"fabpot/php-cs-fixer": "~1.6", | ||
"phpspec/phpspec": "~2.2" | ||
} | ||
} |
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 @@ | ||
extensions: | ||
- Cjm\PhpSpec\Extension\TypeHintedMethodsExtension |
42 changes: 42 additions & 0 deletions
42
spec/Memio/Linter/CollectionCannotHaveNameDuplicatesSpec.php
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,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the memio/linter package. | ||
* | ||
* (c) Loïc Chardonnet <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\Memio\Linter; | ||
|
||
use Memio\Model\Argument; | ||
use Memio\Model\Constant; | ||
use Memio\Model\Method; | ||
use Memio\Model\Property; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class CollectionCannotHaveNameDuplicatesSpec extends ObjectBehavior | ||
{ | ||
function it_is_a_constraint() | ||
{ | ||
$this->shouldImplement('Memio\Validator\Constraint'); | ||
} | ||
|
||
function it_is_fine_with_unique_names(Argument $argument1, Argument $argument2) | ||
{ | ||
$argument1->getName()->willReturn('myArgument1'); | ||
$argument2->getName()->willReturn('myArgument2'); | ||
|
||
$this->validate(array($argument1, $argument2))->shouldHaveType('Memio\Validator\Violation\NoneViolation'); | ||
} | ||
|
||
function it_is_not_fine_with_name_duplicates(Argument $argument1, Argument $argument2) | ||
{ | ||
$argument1->getName()->willReturn('myArgument'); | ||
$argument2->getName()->willReturn('myArgument'); | ||
|
||
$this->validate(array($argument1, $argument2))->shouldHaveType('Memio\Validator\Violation\SomeViolation'); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
spec/Memio/Linter/ConcreteObjectMethodsCannotBeAbstractSpec.php
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,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the memio/linter package. | ||
* | ||
* (c) Loïc Chardonnet <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\Memio\Linter; | ||
|
||
use Memio\Model\Object; | ||
use Memio\Model\Method; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ConcreteObjectMethodsCannotBeAbstractSpec extends ObjectBehavior | ||
{ | ||
function it_is_a_constraint() | ||
{ | ||
$this->shouldImplement('Memio\Validator\Constraint'); | ||
} | ||
|
||
function it_is_fine_with_concrete_object_and_concrete_methods(Object $object, Method $method) | ||
{ | ||
$object->getName()->willReturn('ConcreteClass'); | ||
$object->isAbstract()->willReturn(false); | ||
$object->allMethods()->willReturn(array($method)); | ||
$method->isAbstract()->willReturn(false); | ||
|
||
$this->validate($object)->shouldHaveType('Memio\Validator\Violation\NoneViolation'); | ||
} | ||
|
||
function it_is_fine_with_abstract_objects(Object $object) | ||
{ | ||
$object->isAbstract()->willReturn(true); | ||
|
||
$this->validate($object)->shouldHaveType('Memio\Validator\Violation\NoneViolation'); | ||
} | ||
|
||
function it_is_not_fine_with_concrete_object_and_abstract_methods(Object $object, Method $method) | ||
{ | ||
$object->getName()->willReturn('ConcreteClass'); | ||
$object->isAbstract()->willReturn(false); | ||
$object->allMethods()->willReturn(array($method)); | ||
$method->isAbstract()->willReturn(true); | ||
$method->getName()->willReturn('abstractClass'); | ||
|
||
$this->validate($object)->shouldHaveType('Memio\Validator\Violation\SomeViolation'); | ||
} | ||
} |
Oops, something went wrong.