These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the FOSElasticaBundle package. |
||
5 | * |
||
6 | * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace FOS\ElasticaBundle\Doctrine; |
||
13 | |||
14 | use Doctrine\Common\Persistence\ManagerRegistry; |
||
15 | use FOS\ElasticaBundle\Provider\PagerfantaPager; |
||
16 | use FOS\ElasticaBundle\Provider\PagerProviderInterface; |
||
17 | use Pagerfanta\Adapter\DoctrineODMPhpcrAdapter; |
||
18 | use Pagerfanta\Pagerfanta; |
||
19 | |||
20 | View Code Duplication | final class PHPCRPagerProvider implements PagerProviderInterface |
|
0 ignored issues
–
show
|
|||
21 | { |
||
22 | const ENTITY_ALIAS = 'a'; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $objectClass; |
||
28 | |||
29 | /** |
||
30 | * @var ManagerRegistry |
||
31 | */ |
||
32 | private $doctrine; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $baseOptions; |
||
38 | |||
39 | /** |
||
40 | * @var RegisterListenersService |
||
41 | */ |
||
42 | private $registerListenersService; |
||
43 | |||
44 | /** |
||
45 | * @param ManagerRegistry $doctrine |
||
46 | * @param RegisterListenersService $registerListenersService |
||
47 | * @param string $objectClass |
||
48 | * @param array $baseOptions |
||
49 | */ |
||
50 | 4 | public function __construct(ManagerRegistry $doctrine, RegisterListenersService $registerListenersService, $objectClass, array $baseOptions) |
|
51 | { |
||
52 | 4 | $this->doctrine = $doctrine; |
|
53 | 4 | $this->objectClass = $objectClass; |
|
54 | 4 | $this->baseOptions = $baseOptions; |
|
55 | 4 | $this->registerListenersService = $registerListenersService; |
|
56 | 4 | } |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 3 | public function provide(array $options = array()) |
|
62 | { |
||
63 | 3 | $options = array_replace($this->baseOptions, $options); |
|
64 | |||
65 | 3 | $manager = $this->doctrine->getManagerForClass($this->objectClass); |
|
66 | 3 | $repository = $manager->getRepository($this->objectClass); |
|
67 | |||
68 | 3 | $adapter = new DoctrineODMPhpcrAdapter( |
|
69 | 3 | call_user_func([$repository, $options['query_builder_method']], static::ENTITY_ALIAS) |
|
70 | ); |
||
71 | |||
72 | 3 | $pager = new PagerfantaPager(new Pagerfanta($adapter)); |
|
73 | |||
74 | 3 | $this->registerListenersService->register($manager, $pager, $options); |
|
75 | |||
76 | 3 | return $pager; |
|
77 | } |
||
78 | } |
||
79 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.