Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

New coding standard #100

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ tmp/
zf-mkdoc-theme/
clover.xml
coveralls-upload.json
phpcs.xml
phpunit.xml
vendor
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ To do so:

## Running Coding Standards Checks

This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding
This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding
standards checks, and provides configuration for our selected checks.
`php-cs-fixer` is installed by default via Composer.
`phpcs` is installed by default via Composer.

To run checks only:

```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs
$ composer cs-check
```

To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run`
flag:
`phpcs` also includes a tool for fixing most CS violations, `phpcbf`:


```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs
$ composer cs-fix
```

If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure
If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.

## Recommended Workflow for Contributions
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"ext-phar": "*",
"doctrine/annotations": "~1.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0",
"squizlabs/php_codesniffer": "^2.5",
"phpunit/PHPUnit": "^4.8.21"
"phpunit/PHPUnit": "^4.8.21",
"zendframework/zend-coding-standard": "~1.0.0"
},
"suggest": {
"doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features",
Expand Down
43 changes: 36 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
<exclude-pattern>*/TestAsset/*</exclude-pattern>
</ruleset>
30 changes: 0 additions & 30 deletions phpcs.xml.dist

This file was deleted.

12 changes: 6 additions & 6 deletions src/Annotation/Parser/DoctrineAnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function setDocParser(DocParser $docParser)
*/
public function getDocParser()
{
if (!$this->docParser instanceof DocParser) {
if (! $this->docParser instanceof DocParser) {
$this->setDocParser(new DocParser());
}

Expand All @@ -81,16 +81,16 @@ public function getDocParser()
public function onCreateAnnotation(EventInterface $e)
{
$annotationClass = $e->getParam('class', false);
if (!$annotationClass) {
if (! $annotationClass) {
return false;
}

if (!isset($this->allowedAnnotations[$annotationClass])) {
if (! isset($this->allowedAnnotations[$annotationClass])) {
return false;
}

$annotationString = $e->getParam('raw', false);
if (!$annotationString) {
if (! $annotationString) {
return false;
}

Expand All @@ -107,7 +107,7 @@ public function onCreateAnnotation(EventInterface $e)
}

$annotation = array_shift($annotations);
if (!is_object($annotation)) {
if (! is_object($annotation)) {
return false;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public function registerAnnotation($annotation)
*/
public function registerAnnotations($annotations)
{
if (!is_array($annotations) && !$annotations instanceof Traversable) {
if (! is_array($annotations) && ! $annotations instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: expects an array or Traversable; received "%s"',
__METHOD__,
Expand Down
8 changes: 4 additions & 4 deletions src/Annotation/Parser/GenericAnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GenericAnnotationParser implements ParserInterface
public function onCreateAnnotation(EventInterface $e)
{
$class = $e->getParam('class', false);
if (!$class || !$this->hasAnnotation($class)) {
if (! $class || ! $this->hasAnnotation($class)) {
return false;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public function registerAnnotation($annotation)
$annotation = new $annotation();
}

if (!$annotation instanceof AnnotationInterface) {
if (! $annotation instanceof AnnotationInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: expects an instance of %s\AnnotationInterface; received "%s"',
__METHOD__,
Expand Down Expand Up @@ -122,7 +122,7 @@ public function registerAnnotation($annotation)
*/
public function registerAnnotations($annotations)
{
if (!is_array($annotations) && !$annotations instanceof Traversable) {
if (! is_array($annotations) && ! $annotations instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: expects an array or Traversable; received "%s"',
__METHOD__,
Expand Down Expand Up @@ -166,7 +166,7 @@ public function hasAnnotation($class)
*/
public function setAlias($alias, $class)
{
if (!in_array($class, $this->annotationNames) && !$this->hasAlias($class)) {
if (! in_array($class, $this->annotationNames) && ! $this->hasAlias($class)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: Cannot alias "%s" to "%s", as class "%s" is not currently a registered annotation or alias',
__METHOD__,
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getSourceContent()
*/
public function setOptions($options)
{
if (!is_array($options) && !$options instanceof Traversable) {
if (! is_array($options) && ! $options instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array or Traversable object; received "%s"',
__METHOD__,
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/AbstractMemberGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function setDocBlock($docBlock)
{
if (is_string($docBlock)) {
$docBlock = new DocBlockGenerator($docBlock);
} elseif (!$docBlock instanceof DocBlockGenerator) {
} elseif (! $docBlock instanceof DocBlockGenerator) {
throw new Exception\InvalidArgumentException(sprintf(
'%s is expecting either a string, array or an instance of %s\DocBlockGenerator',
__METHOD__,
Expand Down
20 changes: 10 additions & 10 deletions src/Generator/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static function fromReflection(ClassReflection $classReflection)
*/
public static function fromArray(array $array)
{
if (!isset($array['name'])) {
if (! isset($array['name'])) {
throw new Exception\InvalidArgumentException(
'Class generator requires that a name is provided for this object'
);
Expand Down Expand Up @@ -434,7 +434,7 @@ public function getExtendedClass()
*/
public function hasExtentedClass()
{
return !empty($this->extendedClass);
return ! empty($this->extendedClass);
}

/**
Expand Down Expand Up @@ -572,7 +572,7 @@ public function addConstantFromGenerator(PropertyGenerator $constant)
*/
public function addConstant($name, $value)
{
if (empty($name) || !is_string($name)) {
if (empty($name) || ! is_string($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects string for name',
__METHOD__
Expand Down Expand Up @@ -638,7 +638,7 @@ public function addProperties(array $properties)
*/
public function addProperty($name, $defaultValue = null, $flags = PropertyGenerator::FLAG_PUBLIC)
{
if (!is_string($name)) {
if (! is_string($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s::%s expects string for name',
get_class($this),
Expand Down Expand Up @@ -827,7 +827,7 @@ public function addMethod(
$body = null,
$docBlock = null
) {
if (!is_string($name)) {
if (! is_string($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s::%s expects string for name',
get_class($this),
Expand Down Expand Up @@ -1012,9 +1012,9 @@ public function isSourceDirty()
*/
public function generate()
{
if (!$this->isSourceDirty()) {
if (! $this->isSourceDirty()) {
$output = $this->getSourceContent();
if (!empty($output)) {
if (! empty($output)) {
return $output;
}
}
Expand All @@ -1028,7 +1028,7 @@ public function generate()

$uses = $this->getUses();

if (!empty($uses)) {
if (! empty($uses)) {
foreach ($uses as $use) {
$output .= 'use ' . $use . ';' . self::LINE_FEED;
}
Expand All @@ -1049,13 +1049,13 @@ public function generate()

$output .= static::OBJECT_TYPE . ' ' . $this->getName();

if (!empty($this->extendedClass)) {
if (! empty($this->extendedClass)) {
$output .= ' extends ' . $this->generateShortOrCompleteClassname($this->extendedClass);
}

$implemented = $this->getImplementedInterfaces();

if (!empty($implemented)) {
if (! empty($implemented)) {
$implemented = array_map([$this, 'generateShortOrCompleteClassname'], $implemented);
$output .= ' ' . static::IMPLEMENTS_KEYWORD . ' ' . implode(', ', $implemented);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/DocBlock/Tag/AbstractTypeableTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ abstract class AbstractTypeableTag extends AbstractGenerator
*/
public function __construct($types = [], $description = null)
{
if (!empty($types)) {
if (! empty($types)) {
$this->setTypes($types);
}

if (!empty($description)) {
if (! empty($description)) {
$this->setDescription($description);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/DocBlock/Tag/AuthorTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class AuthorTag extends AbstractGenerator implements TagInterface
*/
public function __construct($authorName = null, $authorEmail = null)
{
if (!empty($authorName)) {
if (! empty($authorName)) {
$this->setAuthorName($authorName);
}

if (!empty($authorEmail)) {
if (! empty($authorEmail)) {
$this->setAuthorEmail($authorEmail);
}
}
Expand Down Expand Up @@ -102,8 +102,8 @@ public function getAuthorName()
public function generate()
{
$output = '@author'
. ((!empty($this->authorName)) ? ' ' . $this->authorName : '')
. ((!empty($this->authorEmail)) ? ' <' . $this->authorEmail . '>' : '');
. ((! empty($this->authorName)) ? ' ' . $this->authorName : '')
. ((! empty($this->authorEmail)) ? ' <' . $this->authorEmail . '>' : '');

return $output;
}
Expand Down
Loading