Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
23 | class RepositoryFactory implements ContainerAwareInterface |
||
24 | { |
||
25 | use ContainerAwareTrait; |
||
26 | |||
27 | /** |
||
28 | * @var \eZ\Publish\Core\MVC\ConfigResolverInterface |
||
29 | */ |
||
30 | private $configResolver; |
||
31 | |||
32 | /** |
||
33 | * Collection of fieldTypes, lazy loaded via a closure. |
||
34 | * |
||
35 | * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeCollectionFactory |
||
36 | */ |
||
37 | protected $fieldTypeCollectionFactory; |
||
38 | |||
39 | /** |
||
40 | * Collection of fieldTypes, lazy loaded via a closure. |
||
41 | * |
||
42 | * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeNameableCollectionFactory |
||
43 | */ |
||
44 | protected $fieldTypeNameableCollectionFactory; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | private $repositoryClass; |
||
50 | |||
51 | /** |
||
52 | * Collection of limitation types for the RoleService. |
||
53 | * |
||
54 | * @var \eZ\Publish\SPI\Limitation\Type[] |
||
55 | */ |
||
56 | protected $roleLimitations = array(); |
||
57 | |||
58 | /** |
||
59 | * @var array |
||
60 | */ |
||
61 | private $policyMap; |
||
62 | |||
63 | public function __construct( |
||
76 | |||
77 | /** |
||
78 | * Builds the main repository, heart of eZ Publish API. |
||
79 | * |
||
80 | * This always returns the true inner Repository, please depend on ezpublish.api.repository and not this method |
||
81 | * directly to make sure you get an instance wrapped inside Signal / Cache / * functionality. |
||
82 | * |
||
83 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
84 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
85 | * |
||
86 | * @return \eZ\Publish\API\Repository\Repository |
||
87 | */ |
||
88 | public function buildRepository(PersistenceHandler $persistenceHandler, SearchHandler $searchHandler) |
||
114 | |||
115 | /** |
||
116 | * Registers a limitation type for the RoleService. |
||
117 | * |
||
118 | * @param string $limitationName |
||
119 | * @param \eZ\Publish\SPI\Limitation\Type $limitationType |
||
120 | */ |
||
121 | public function registerLimitationType($limitationName, SPILimitationType $limitationType) |
||
125 | |||
126 | /** |
||
127 | * Returns a service based on a name string (content => contentService, etc). |
||
128 | * |
||
129 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
130 | * @param string $serviceName |
||
131 | * |
||
132 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException |
||
133 | * |
||
134 | * @return mixed |
||
135 | */ |
||
136 | View Code Duplication | public function buildService(Repository $repository, $serviceName) |
|
145 | } |
||
146 |