Skip to content

Commit

Permalink
Merge pull request #1572 from jewome62/php-inspect-extended
Browse files Browse the repository at this point in the history
PHP Inspect Extended fix
  • Loading branch information
soyuka committed Dec 19, 2017
2 parents 38d2168 + da52ae7 commit 81770d5
Show file tree
Hide file tree
Showing 60 changed files with 131 additions and 144 deletions.
2 changes: 0 additions & 2 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,6 @@ public function createPeopleWithPets()
*/
public function thereIsDummyDateObjectsWithDummyDate(int $nb)
{
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];

for ($i = 1; $i <= $nb; ++$i) {
$date = new \DateTime(sprintf('2015-04-%d', $i), new \DateTimeZone('UTC'));

Expand Down
7 changes: 0 additions & 7 deletions features/bootstrap/SwaggerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@
use Behatch\Context\RestContext;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\ExpectationFailedException;
use Symfony\Component\PropertyAccess\PropertyAccess;

final class SwaggerContext implements Context
{
/**
* @var RestContext
*/
private $restContext;
private $propertyAccessor;

public function __construct()
{
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
}

/**
* Gives access to the Behatch context.
Expand Down
2 changes: 1 addition & 1 deletion src/Api/CachedIdentifiersExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getIdentifiersFromItem($item): array
foreach ($keys as $propertyName) {
$identifiers[$propertyName] = $this->propertyAccessor->getValue($item, $propertyName);

if (!is_object($identifiers[$propertyName])) {
if (!\is_object($identifiers[$propertyName])) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/FilterLocatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait FilterLocatorTrait
*/
private function setFilterLocator($filterLocator = null, bool $allowNull = false)
{
if ($filterLocator instanceof ContainerInterface || $filterLocator instanceof FilterCollection || null === $filterLocator && $allowNull) {
if ($filterLocator instanceof ContainerInterface || $filterLocator instanceof FilterCollection || (null === $filterLocator && $allowNull)) {
if ($filterLocator instanceof FilterCollection) {
@trigger_error(sprintf('The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.', FilterCollection::class, ContainerInterface::class), E_USER_DEPRECATED);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/IdentifiersExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getIdentifiersFromItem($item): array
continue;
}
$identifier = $identifiers[$propertyName] = $this->propertyAccessor->getValue($item, $propertyName);
if (!is_object($identifier)) {
if (!\is_object($identifier)) {
continue;
} elseif (method_exists($identifier, '__toString')) {
$identifiers[$propertyName] = (string) $identifier;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/OperationTypeDeprecationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class OperationTypeDeprecationHelper
*/
public static function getOperationType($operationType): string
{
if (is_bool($operationType)) {
if (\is_bool($operationType)) {
@trigger_error('Using a boolean for the Operation Type is deprecated since API Platform 2.1 and will not be possible anymore in API Platform 3', E_USER_DEPRECATED);

$operationType = $operationType ? OperationType::COLLECTION : OperationType::ITEM;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/ResourceClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName
*/
public function getResourceClass($value, string $resourceClass = null, bool $strict = false): string
{
if (is_object($value) && !$value instanceof \Traversable) {
if (\is_object($value) && !$value instanceof \Traversable) {
$typeToFind = $type = $this->getObjectClass($value);
if (null === $resourceClass) {
$resourceClass = $typeToFind;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function addTagsFor($value)
return;
}

if (!is_array($value) && !$value instanceof \Traversable) {
if (!\is_array($value) && !$value instanceof \Traversable) {
$this->addTagForItem($value);

return;
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/EventListener/WriteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
private function getManager(string $resourceClass, $data)
{
$objectManager = $this->managerRegistry->getManagerForClass($resourceClass);
if (null === $objectManager || !is_object($data)) {
if (null === $objectManager || !\is_object($data)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Orm/Extension/OrderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGenerator
$defaultOrder = $this->resourceMetadataFactory->create($resourceClass)->getAttribute('order');
if (null !== $defaultOrder) {
foreach ($defaultOrder as $field => $order) {
if (is_int($field)) {
if (\is_int($field)) {
// Default direction
$field = $order;
$order = 'ASC';
Expand Down
32 changes: 16 additions & 16 deletions src/Bridge/Doctrine/Orm/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ protected function getClassMetadata(string $resourceClass): ClassMetadata
*/
protected function isPropertyEnabled(string $property/*, string $resourceClass*/): bool
{
if (func_num_args() > 1) {
if (\func_num_args() > 1) {
$resourceClass = func_get_arg(1);
} else {
if (__CLASS__ !== get_class($this)) {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
Expand Down Expand Up @@ -151,10 +151,10 @@ protected function isPropertyMapped(string $property, string $resourceClass, boo
*/
protected function isPropertyNested(string $property/*, string $resourceClass*/): bool
{
if (func_num_args() > 1) {
$resourceClass = func_get_arg(1);
if (\func_num_args() > 1) {
$resourceClass = (string) func_get_arg(1);
} else {
if (__CLASS__ !== get_class($this)) {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
Expand Down Expand Up @@ -224,10 +224,10 @@ protected function splitPropertyParts(string $property/*, string $resourceClass*
{
$parts = explode('.', $property);

if (func_num_args() > 1) {
if (\func_num_args() > 1) {
$resourceClass = func_get_arg(1);
} else {
if (__CLASS__ !== get_class($this)) {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
Expand All @@ -237,7 +237,7 @@ protected function splitPropertyParts(string $property/*, string $resourceClass*

if (!isset($resourceClass)) {
return [
'associations' => array_slice($parts, 0, -1),
'associations' => \array_slice($parts, 0, -1),
'field' => end($parts),
];
}
Expand All @@ -252,13 +252,13 @@ protected function splitPropertyParts(string $property/*, string $resourceClass*
}
}

if ($slice === count($parts)) {
if ($slice === \count($parts)) {
$slice -= 1;
}

return [
'associations' => array_slice($parts, 0, $slice),
'field' => implode('.', array_slice($parts, $slice)),
'associations' => \array_slice($parts, 0, $slice),
'field' => implode('.', \array_slice($parts, $slice)),
];
}

Expand All @@ -271,10 +271,10 @@ protected function splitPropertyParts(string $property/*, string $resourceClass*
*/
protected function extractProperties(Request $request/*, string $resourceClass*/): array
{
if (func_num_args() > 1) {
$resourceClass = func_get_arg(1);
if (\func_num_args() > 1) {
$resourceClass = (string) func_get_arg(1);
} else {
if (__CLASS__ !== get_class($this)) {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
Expand Down Expand Up @@ -316,10 +316,10 @@ protected function extractProperties(Request $request/*, string $resourceClass*/
*/
protected function addJoinsForNestedProperty(string $property, string $rootAlias, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator/*, string $resourceClass*/): array
{
if (func_num_args() > 4) {
if (\func_num_args() > 4) {
$resourceClass = func_get_arg(4);
} else {
if (__CLASS__ !== get_class($this)) {
if (__CLASS__ !== \get_class($this)) {
$r = new \ReflectionMethod($this, __FUNCTION__);
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Method %s() will have a fifth `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/Orm/Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
return;
}

if (in_array($value, ['true', '1'], true)) {
if (\in_array($value, ['true', '1'], true)) {
$value = true;
} elseif (in_array($value, ['false', '0'], true)) {
} elseif (\in_array($value, ['false', '0'], true)) {
$value = false;
} else {
$this->logger->notice('Invalid filter ignored', [
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/Doctrine/Orm/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function filterProperty(string $property, $values, QueryBuilder $query
{
// Expect $values to be an array having the period as keys and the date value as values
if (
!is_array($values) ||
!\is_array($values) ||
!$this->isPropertyEnabled($property, $resourceClass) ||
!$this->isPropertyMapped($property, $resourceClass) ||
!$this->isDateField($property, $resourceClass)
Expand Down Expand Up @@ -189,8 +189,8 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
if (null === $nullManagement || self::EXCLUDE_NULL === $nullManagement) {
$queryBuilder->andWhere($baseWhere);
} elseif (
(in_array($operator, [self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true) && self::INCLUDE_NULL_BEFORE === $nullManagement) ||
(in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true) && self::INCLUDE_NULL_AFTER === $nullManagement)
(\in_array($operator, [self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true) && self::INCLUDE_NULL_BEFORE === $nullManagement) ||
(\in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true) && self::INCLUDE_NULL_AFTER === $nullManagement)
) {
$queryBuilder->andWhere($queryBuilder->expr()->orX(
$baseWhere,
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/Orm/Filter/ExistsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
return;
}

if (in_array($value[self::QUERY_PARAMETER_KEY], ['true', '1', '', null], true)) {
if (\in_array($value[self::QUERY_PARAMETER_KEY], ['true', '1', '', null], true)) {
$value = true;
} elseif (in_array($value[self::QUERY_PARAMETER_KEY], ['false', '0'], true)) {
} elseif (\in_array($value[self::QUERY_PARAMETER_KEY], ['false', '0'], true)) {
$value = false;
} else {
$this->logger->notice('Invalid filter ignored', [
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/Doctrine/Orm/Filter/OrderFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(ManagerRegistry $managerRegistry, RequestStack $requ
if (null !== $properties) {
$properties = array_map(function ($propertyOptions) {
// shorthand for default direction
if (is_string($propertyOptions)) {
if (\is_string($propertyOptions)) {
$propertyOptions = [
'default_direction' => $propertyOptions,
];
Expand Down Expand Up @@ -115,7 +115,7 @@ protected function filterProperty(string $property, $direction, QueryBuilder $qu
}

$direction = strtoupper($direction);
if (!in_array($direction, ['ASC', 'DESC'], true)) {
if (!\in_array($direction, ['ASC', 'DESC'], true)) {
return;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ protected function filterProperty(string $property, $direction, QueryBuilder $qu
protected function extractProperties(Request $request/*, string $resourceClass*/): array
{
$properties = $request->query->get($this->orderParameterName, []);
if (!is_array($properties)) {
if (!\is_array($properties)) {
return [];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/Orm/Filter/RangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getDescription(string $resourceClass): array
protected function filterProperty(string $property, $values, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
{
if (
!is_array($values) ||
!\is_array($values) ||
!$this->isPropertyEnabled($property, $resourceClass) ||
!$this->isPropertyMapped($property, $resourceClass)
) {
Expand Down Expand Up @@ -107,7 +107,7 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
case self::PARAMETER_BETWEEN:
$rangeValue = explode('..', $value);

if (2 !== count($rangeValue)) {
if (2 !== \count($rangeValue)) {
$this->logger->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(sprintf('Invalid format for "[%s]", expected "<min>..<max>"', $operator)),
]);
Expand Down
8 changes: 4 additions & 4 deletions src/Bridge/Doctrine/Orm/Filter/SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private function getType(string $doctrineType): string
return 'float';
}

if (defined(Type::class.'::DATE_IMMUTABLE')) {
if (\defined(Type::class.'::DATE_IMMUTABLE')) {
switch ($doctrineType) {
case Type::DATE_IMMUTABLE:
case Type::TIME_IMMUTABLE:
Expand Down Expand Up @@ -227,7 +227,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
$caseSensitive = false;
}

if (1 === count($values)) {
if (1 === \count($values)) {
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $values[0], $caseSensitive);

return;
Expand Down Expand Up @@ -275,7 +275,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
$associationField = $field;
}

if (1 === count($values)) {
if (1 === \count($values)) {
$queryBuilder
->andWhere(sprintf('%s.%s = :%s', $associationAlias, $associationField, $valueParameter))
->setParameter($valueParameter, $values[0]);
Expand Down Expand Up @@ -388,7 +388,7 @@ protected function getIdFromValue(string $value)
protected function normalizeValues(array $values): array
{
foreach ($values as $key => $value) {
if (!is_int($key) || !is_string($value)) {
if (!\is_int($key) || !\is_string($value)) {
unset($values[$key]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/Orm/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(DoctrineOrmPaginator $paginator)
$query = $paginator->getQuery();
$this->firstResult = $query->getFirstResult();
$this->maxResults = $query->getMaxResults();
$this->totalItems = count($paginator);
$this->totalItems = \count($paginator);
}

/**
Expand Down Expand Up @@ -111,6 +111,6 @@ public function getIterator()
*/
public function count()
{
return count($this->getIterator());
return \count($this->getIterator());
}
}
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Orm/SubresourceDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getSubresource(string $resourceClass, array $identifiers, array
$previousQueryBuilder = null;
$previousAlias = null;

$num = count($context['identifiers']);
$num = \count($context['identifiers']);

while ($num--) {
list($identifier, $identifierResourceClass) = $context['identifiers'][$num];
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/Orm/Util/EagerLoadingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private function getBooleanOperationAttribute(string $resourceClass, array $opti
$attribute = $resourceMetadata->getAttribute($attributeName);
}

return is_bool($attribute) ? $attribute : $default;
return \is_bool($attribute) ? $attribute : $default;
}

/**
Expand All @@ -98,7 +98,7 @@ private function hasFetchEagerAssociation(EntityManager $em, ClassMetadataInfo $

$related = $em->getClassMetadata($mapping['targetEntity']);

if (in_array($related->name, $checked, true)) {
if (\in_array($related->name, $checked, true)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Orm/Util/IdentifierManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function normalizeIdentifiers($id, ObjectManager $manager, string $resou
$isOrm = interface_exists(EntityManagerInterface::class) && $manager instanceof EntityManagerInterface;
$platform = $isOrm ? $manager->getConnection()->getDatabasePlatform() : null;

if (count($doctrineIdentifierFields) > 1) {
if (\count($doctrineIdentifierFields) > 1) {
$identifiersMap = [];

// first transform identifiers to a proper key/value array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function getApiDoc(bool $collection, string $resourceClass, ResourceMeta
*/
private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortName)
{
if (!isset($hydraApiDoc['hydra:supportedClass']) || !is_array($hydraApiDoc['hydra:supportedClass'])) {
if (!isset($hydraApiDoc['hydra:supportedClass']) || !\is_array($hydraApiDoc['hydra:supportedClass'])) {
return null;
}

Expand All @@ -188,7 +188,7 @@ private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortNa
*/
private function getOperationHydraDoc(string $method, array $hydraDoc): array
{
if (!isset($hydraDoc['hydra:supportedOperation']) || !is_array($hydraDoc['hydra:supportedOperation'])) {
if (!isset($hydraDoc['hydra:supportedOperation']) || !\is_array($hydraDoc['hydra:supportedOperation'])) {
return [];
}

Expand All @@ -212,7 +212,7 @@ private function getOperationHydraDoc(string $method, array $hydraDoc): array
*/
private function getCollectionOperationHydraDoc(string $shortName, string $method, array $hydraEntrypointDoc): array
{
if (!isset($hydraEntrypointDoc['hydra:supportedProperty']) || !is_array($hydraEntrypointDoc['hydra:supportedProperty'])) {
if (!isset($hydraEntrypointDoc['hydra:supportedProperty']) || !\is_array($hydraEntrypointDoc['hydra:supportedProperty'])) {
return [];
}

Expand Down
Loading

0 comments on commit 81770d5

Please sign in to comment.