Skip to content

Commit bc52cac

Browse files
authored
Merge pull request #3493 from soyuka/2.5
2.5
2 parents aad8a84 + bda66b7 commit bc52cac

File tree

10 files changed

+27
-53
lines changed

10 files changed

+27
-53
lines changed

.php_cs.dist

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ return PhpCsFixer\Config::create()
108108
'property',
109109
],
110110
],
111-
'void_return' => false, // BC breaks; to be done in API Platform 3.0
111+
'void_return' => false, // BC breaks; to be done in API Platform 3.0,
112+
// removed get_class_this see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4921
113+
'function_to_constant' => [
114+
'functions' => [
115+
'get_called_class',
116+
'get_class',
117+
'php_sapi_name',
118+
'phpversion',
119+
'pi'
120+
]
121+
]
112122
])
113123
->setFinder($finder);

src/Annotation/ApiResource.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ final class ApiResource
208208
/**
209209
* @see https://api-platform.com/docs/core/mercure
210210
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
211-
*
212-
* @var mixed
213211
*/
214212
private $mercure;
215213

@@ -384,8 +382,6 @@ final class ApiResource
384382
/**
385383
* @see https://api-platform.com/docs/core/validation/#using-validation-groups
386384
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
387-
*
388-
* @var mixed
389385
*/
390386
private $validationGroups;
391387

src/Annotation/AttributesHydratorTrait.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
*/
1111

1212
declare(strict_types=1);
13-
/*
14-
* This file is part of the API Platform project.
15-
*
16-
* (c) Kévin Dunglas <[email protected]>
17-
*
18-
* For the full copyright and license information, please view the LICENSE
19-
* file that was distributed with this source code.
20-
*/
2113

2214
namespace ApiPlatform\Core\Annotation;
2315

src/Bridge/Doctrine/Orm/Filter/SearchFilter.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
9292
$caseSensitive = true;
9393
$metadata = $this->getNestedMetadata($resourceClass, $associations);
9494

95-
if ($metadata->hasField($field)) {
96-
if ('id' === $field) {
97-
$values = array_map([$this, 'getIdFromValue'], $values);
98-
}
95+
$doctrineTypeField = $this->getDoctrineFieldType($property, $resourceClass);
96+
$values = array_map([$this, 'getIdFromValue'], $values);
9997

100-
if (!$this->hasValidValues($values, $this->getDoctrineFieldType($property, $resourceClass))) {
98+
if ($metadata->hasField($field)) {
99+
if (!$this->hasValidValues($values, $doctrineTypeField)) {
101100
$this->logger->notice('Invalid filter ignored', [
102101
'exception' => new InvalidArgumentException(sprintf('Values for field "%s" are not valid according to the doctrine type.', $field)),
103102
]);
@@ -114,7 +113,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
114113
}
115114

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

119118
return;
120119
}
@@ -140,9 +139,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
140139
return;
141140
}
142141

143-
$values = array_map([$this, 'getIdFromValue'], $values);
144142
$associationFieldIdentifier = 'id';
145-
$doctrineTypeField = $this->getDoctrineFieldType($property, $resourceClass);
146143

147144
if (null !== $this->identifiersExtractor) {
148145
$associationResourceClass = $metadata->getAssociationTargetClass($field);
@@ -171,11 +168,11 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
171168
if (1 === \count($values)) {
172169
$queryBuilder
173170
->andWhere(sprintf('%s.%s = :%s', $associationAlias, $associationField, $valueParameter))
174-
->setParameter($valueParameter, $values[0]);
171+
->setParameter($valueParameter, $values[0], $doctrineTypeField);
175172
} else {
176173
$queryBuilder
177174
->andWhere(sprintf('%s.%s IN (:%s)', $associationAlias, $associationField, $valueParameter))
178-
->setParameter($valueParameter, $values);
175+
->setParameter($valueParameter, $values, $doctrineTypeField);
179176
}
180177
}
181178

@@ -184,7 +181,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
184181
*
185182
* @throws InvalidArgumentException If strategy does not exist
186183
*/
187-
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive)
184+
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $fieldType, $value, bool $caseSensitive)
188185
{
189186
$wrapCase = $this->createWrapCase($caseSensitive);
190187
$valueParameter = $queryNameGenerator->generateParameterName($field);
@@ -194,27 +191,27 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
194191
case self::STRATEGY_EXACT:
195192
$queryBuilder
196193
->andWhere(sprintf($wrapCase('%s.%s').' = '.$wrapCase(':%s'), $alias, $field, $valueParameter))
197-
->setParameter($valueParameter, $value);
194+
->setParameter($valueParameter, $value, $fieldType);
198195
break;
199196
case self::STRATEGY_PARTIAL:
200197
$queryBuilder
201198
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s, \'%%\')'), $alias, $field, $valueParameter))
202-
->setParameter($valueParameter, $value);
199+
->setParameter($valueParameter, $value, $fieldType);
203200
break;
204201
case self::STRATEGY_START:
205202
$queryBuilder
206203
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(:%s, \'%%\')'), $alias, $field, $valueParameter))
207-
->setParameter($valueParameter, $value);
204+
->setParameter($valueParameter, $value, $fieldType);
208205
break;
209206
case self::STRATEGY_END:
210207
$queryBuilder
211208
->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s)'), $alias, $field, $valueParameter))
212-
->setParameter($valueParameter, $value);
209+
->setParameter($valueParameter, $value, $fieldType);
213210
break;
214211
case self::STRATEGY_WORD_START:
215212
$queryBuilder
216213
->andWhere(sprintf($wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(:%3$s, \'%%\')').' OR '.$wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(\'%% \', :%3$s, \'%%\')'), $alias, $field, $valueParameter))
217-
->setParameter($valueParameter, $value);
214+
->setParameter($valueParameter, $value, $fieldType);
218215
break;
219216
default:
220217
throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));

src/Bridge/Symfony/Bundle/Resources/views/SwaggerUi/index.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
<br>
7171
Other API docs:
7272
{% set active_ui = app.request.get('ui', 'swagger_ui') %}
73-
{% if swaggerUiEnabled and active_ui != 'swagger_ui' %}<a href="{{ path('api_entrypoint') }}">Swagger UI</a>{% endif %}
74-
{% if reDocEnabled and active_ui != 're_doc' %}<a href="{{ path('api_entrypoint', {'ui': 're_doc'}) }}">ReDoc</a>{% endif %}
73+
{% if swaggerUiEnabled and active_ui != 'swagger_ui' %}<a href="{{ path('api_doc') }}">Swagger UI</a>{% endif %}
74+
{% if reDocEnabled and active_ui != 're_doc' %}<a href="{{ path('api_doc', {'ui': 're_doc'}) }}">ReDoc</a>{% endif %}
7575
{% if not graphqlEnabled %}<a href="javascript:alert('GraphQL support is not enabled, see https://api-platform.com/docs/core/graphql/')">GraphiQL</a>{% endif %}
7676
{% if graphiQlEnabled %}<a href="{{ path('api_graphql_graphiql') }}">GraphiQL</a>{% endif %}
7777
{% if graphQlPlaygroundEnabled %}<a href="{{ path('api_graphql_graphql_playground') }}">GraphQL Playground</a>{% endif %}

src/Bridge/Symfony/Bundle/Test/BrowserKitAssertionsTrait.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111

1212
declare(strict_types=1);
1313

14-
/*
15-
* This file is part of the Symfony package.
16-
*
17-
* (c) Fabien Potencier <[email protected]>
18-
*
19-
* For the full copyright and license information, please view the LICENSE
20-
* file that was distributed with this source code.
21-
*/
22-
2314
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Test;
2415

2516
use PHPUnit\Framework\Constraint\LogicalAnd;

src/Hydra/Serializer/PartialCollectionViewNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function normalize($object, $format = null, array $context = [])
113113
$data['hydra:view']['hydra:previous'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage - 1.);
114114
}
115115

116-
if (null !== $lastPage && $currentPage !== $lastPage || null === $lastPage && $pageTotalItems >= $itemsPerPage) {
116+
if (null !== $lastPage && $currentPage < $lastPage || null === $lastPage && $pageTotalItems >= $itemsPerPage) {
117117
$data['hydra:view']['hydra:next'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage + 1.);
118118
}
119119
}

tests/Bridge/Symfony/Validator/Exception/ValidationExceptionTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
*/
1111

1212
declare(strict_types=1);
13-
/*
14-
* This file is part of the API Platform project.
15-
*
16-
* (c) Kévin Dunglas <[email protected]>
17-
*
18-
* For the full copyright and license information, please view the LICENSE
19-
* file that was distributed with this source code.
20-
*/
2113

2214
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Validator\Exception;
2315

tests/Fixtures/TestBundle/Document/ContainNonResource.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
class ContainNonResource
3535
{
3636
/**
37-
* @var mixed
38-
*
3937
* @ODM\Id(strategy="INCREMENT", type="integer")
4038
*
4139
* @Groups("contain_non_resource")

tests/Fixtures/TestBundle/Entity/ContainNonResource.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
class ContainNonResource
3535
{
3636
/**
37-
* @var mixed
38-
*
3937
* @ORM\Column(type="integer")
4038
* @ORM\Id
4139
* @ORM\GeneratedValue(strategy="AUTO")

0 commit comments

Comments
 (0)