Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/401' into 2.0.x
Browse files Browse the repository at this point in the history
Close Roave#401
  • Loading branch information
Ocramius committed Feb 5, 2018
2 parents 9583638 + 8eca1df commit efc45b5
Show file tree
Hide file tree
Showing 208 changed files with 1,574 additions and 1,631 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
php: 7.1
env: DEPENDENCIES=""
before_script:
- travis_retry composer require --dev --prefer-dist --prefer-stable doctrine/coding-standard:^1.0.0 slevomat/coding-standard:^4.0.0
- travis_retry composer require --dev --prefer-dist --prefer-stable doctrine/coding-standard:~2.1.0
script: vendor/bin/phpcs

- stage: Static Analysis
Expand All @@ -96,9 +96,6 @@ jobs:
- vendor/bin/phpunit --coverage-text --coverage-clover=clover.xml
- php ocular.phar code-coverage:upload --format=php-clover clover.xml

allow_failures:
- php: 7.2

cache:
directories:
- $HOME/.composer/cache
9 changes: 9 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ This document serves as a reference to upgrade your current
BetterReflection installation if improvements, deprecations
or backwards compatibility (BC) breakages occur.

## 3.0.0

### BC breaks

* Method `Roave\BetterReflection\Reflection\Adapter\ReflectionClass#getProperty()` throws exception
when property does not exist to be compatible with core reflection.
* Method `Roave\BetterReflection\Reflection\Adapter\ReflectionObject#getProperty()` throws exception
when property does not exist to be compatible with core reflection.

## 2.0.0

### Namespace change
Expand Down
16 changes: 12 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ environment:
php_version: 7.1
- dependencies: highest
php_version: 7.1
- dependencies: lowest
php_version: 7.2
- dependencies: highest
php_version: 7.2

project_directory: c:\projects\better-reflection
composer_directory: c:\tools\composer
composer_executable: c:\tools\composer\composer.phar
composer_installer: c:\tools\composer\installer.php
php_directory: c:\tools\php71
php_root_directory: c:\tools\php
matrix:
fast_finish: true
clone_folder: c:\projects\better-reflection
cache:
- c:\tools\composer -> appveyor.yml
- '%LOCALAPPDATA%\Composer -> appveyor.yml'
- c:\tools\php71 -> appveyor.yml
- c:\tools\php -> appveyor.yml
init:
- ps: $Env:php_directory = $Env:php_root_directory + '\' + $Env:php_version
- ps: $Env:exact_php_version = (((choco search php --exact --all-versions --limit-output | Select-String -pattern $Env:php_version) -replace '[php|]', '') | %{ New-Object System.Version $_ } | Sort-Object | Select-Object -Last 1).ToString()
- ps: $Env:PATH = $Env:php_directory + ';' + $Env:composer_directory + ';' + $Env:PATH
- ps: $Env:ANSICON = '121x90 (121x90)'
install:
# Install PHP
- ps: If ((Test-Path $Env:php_directory) -eq $False) { appveyor-retry cinst -y OpenSSL.Light } Else { appveyor-retry choco upgrade OpenSSL.Light }
- ps: If ((Test-Path $Env:php_directory) -eq $False) { appveyor-retry cinst -y php } Else { appveyor-retry choco upgrade php }
- ps: If ((Test-Path $Env:php_directory) -eq $False) { New-Item -Path $Env:php_directory -ItemType 'directory' }
- ps: appveyor-retry choco upgrade OpenSSL.Light --yes
- ps: $php_install_parameters = '"/DontAddToPath /InstallDir:' + $Env:php_directory + '"'
- ps: appveyor-retry choco upgrade php --yes --version=$Env:exact_php_version --params=$php_install_parameters

# Prepare PHP
- ps: cd $Env:php_directory
Expand Down
4 changes: 2 additions & 2 deletions docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ways:
class MyClass
{
/**
* @param array $myMethod
* @param array $myParameter
*/
public function myMethod(array $myMethod = [])
public function myMethod(array $myParameter = [])
{
// ... stuff ...
}
Expand Down
84 changes: 5 additions & 79 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,93 +18,19 @@
<exclude-pattern>src/SourceLocator/Type/AutoloadSourceLocator.php</exclude-pattern>
</rule>

<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Squiz.Classes.SelfMemberReference"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage">
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
</rule>
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
<properties>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
<!-- Turned off by PSR2 -> turning on with default severity -->
<severity>5</severity>
</rule>

<config name="installed_paths" value="../../slevomat/coding-standard"/><!-- relative path from PHPCS source location -->
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property name="forbiddenAnnotations" type="array" value="
@access,
@package,
@subpage,
@type,
"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators">
<exclude-pattern>src/NodeCompiler/CompileNodeToValue.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants"/>
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions"/>
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="allowFullyQualifiedGlobalFunctions" value="true"/>
<property name="allowFullyQualifiedGlobalConstants" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
<property name="enableObjectTypeHint" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessDocComment"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint">
<exclude-pattern>src/Reflection/Adapter/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint">
<exclude-pattern>src/Reflection/Adapter/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
<properties>
<property name="linesCountAfterOpeningBrace" value="0"/>
<property name="linesCountBeforeClosingBrace" value="0"/>
</properties>
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification">
<!-- It's useless to add "@return mixed[]" to all data providers -->
<exclude-pattern>test/</exclude-pattern>
</rule>
</ruleset>
1 change: 1 addition & 0 deletions src/BetterReflection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection;
Expand Down
4 changes: 3 additions & 1 deletion src/Identifier/Exception/InvalidIdentifierName.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection\Identifier\Exception;

use InvalidArgumentException;
use function sprintf;

class InvalidIdentifierName extends InvalidArgumentException
{
public static function fromInvalidName(string $name) : self
{
return new self(\sprintf('Invalid identifier name "%s"', $name));
return new self(sprintf('Invalid identifier name "%s"', $name));
}
}
16 changes: 9 additions & 7 deletions src/Identifier/Identifier.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection\Identifier;

use Roave\BetterReflection\Identifier\Exception\InvalidIdentifierName;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunctionAbstract;
use function ltrim;
use function preg_match;
use function strpos;

class Identifier
{
Expand All @@ -24,26 +28,24 @@ class Identifier
private $type;

/**
* @param string $name
* @param IdentifierType $type
*
* @throws InvalidIdentifierName
*/
public function __construct(string $name, IdentifierType $type)
{
$this->type = $type;

if (self::WILDCARD === $name
|| ReflectionFunctionAbstract::CLOSURE_NAME === $name
|| 0 === \strpos($name, ReflectionClass::ANONYMOUS_CLASS_NAME_PREFIX)
if ($name === self::WILDCARD
|| $name === ReflectionFunctionAbstract::CLOSURE_NAME
|| strpos($name, ReflectionClass::ANONYMOUS_CLASS_NAME_PREFIX) === 0
) {
$this->name = $name;
return;
}

$name = \ltrim($name, '\\');
$name = ltrim($name, '\\');

if ( ! \preg_match(self::VALID_NAME_REGEXP, $name)) {
if (! preg_match(self::VALID_NAME_REGEXP, $name)) {
throw InvalidIdentifierName::fromInvalidName($name);
}

Expand Down
18 changes: 9 additions & 9 deletions src/Identifier/IdentifierType.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection\Identifier;
Expand All @@ -7,6 +8,8 @@
use Roave\BetterReflection\Reflection\Reflection;
use Roave\BetterReflection\Reflection\ReflectionClass;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use function array_key_exists;
use function sprintf;

class IdentifierType
{
Expand All @@ -25,8 +28,8 @@ class IdentifierType

public function __construct(string $type = self::IDENTIFIER_CLASS)
{
if ( ! \array_key_exists($type, self::VALID_TYPES)) {
throw new InvalidArgumentException(\sprintf(
if (! array_key_exists($type, self::VALID_TYPES)) {
throw new InvalidArgumentException(sprintf(
'%s is not a valid identifier type',
$type
));
Expand All @@ -41,27 +44,24 @@ public function getName() : string

public function isClass() : bool
{
return self::IDENTIFIER_CLASS === $this->name;
return $this->name === self::IDENTIFIER_CLASS;
}

public function isFunction() : bool
{
return self::IDENTIFIER_FUNCTION === $this->name;
return $this->name === self::IDENTIFIER_FUNCTION;
}

/**
* Check to see if a reflector is of a valid type specified by this identifier.
*
* @param Reflection $reflector
* @return bool
*/
public function isMatchingReflector(Reflection $reflector) : bool
{
if (self::IDENTIFIER_CLASS === $this->name) {
if ($this->name === self::IDENTIFIER_CLASS) {
return $reflector instanceof ReflectionClass;
}

if (self::IDENTIFIER_FUNCTION === $this->name) {
if ($this->name === self::IDENTIFIER_FUNCTION) {
return $reflector instanceof ReflectionFunction;
}

Expand Down
Loading

0 comments on commit efc45b5

Please sign in to comment.