RandomOrderFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 10 1
A filterProperty() 0 9 3
1
<?php
2
3
namespace ControleOnline\Filter;
4
5
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\AbstractFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm...yNameGeneratorInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use ApiPlatform\Metadata\Operation;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Operation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Doctrine\ORM\QueryBuilder;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\QueryBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
final class RandomOrderFilter extends AbstractFilter
11
{
12
    protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
13
    {
14
        // Verifica se o parâmetro "random" foi passado na URL
15
        if ($property !== 'random' || $value !== 'true') {
16
            return;
17
        }
18
19
        // Adiciona a ordenação aleatória à query
20
        $queryBuilder->orderBy('RAND()');
21
    }
22
23
    public function getDescription(string $resourceClass): array
24
    {
25
        return [
26
            'random' => [
27
                'property' => null,
28
                'type' => 'string',
29
                'required' => false,
30
                'description' => 'Pass "true" to sort results randomly.',
31
                'openapi' => [
32
                    'example' => 'true',
33
                ],
34
            ],
35
        ];
36
    }
37
}
38