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 |
||
24 | class RepositoryFactory implements ContainerAwareInterface |
||
25 | { |
||
26 | use ContainerAwareTrait; |
||
27 | |||
28 | /** |
||
29 | * @var \eZ\Publish\Core\MVC\ConfigResolverInterface |
||
30 | */ |
||
31 | private $configResolver; |
||
32 | |||
33 | /** |
||
34 | * Collection of fieldTypes, lazy loaded via a closure. |
||
35 | * |
||
36 | * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeCollectionFactory |
||
37 | */ |
||
38 | protected $fieldTypeCollectionFactory; |
||
39 | |||
40 | /** |
||
41 | * Collection of fieldTypes, lazy loaded via a closure. |
||
42 | * |
||
43 | * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeNameableCollectionFactory |
||
44 | */ |
||
45 | protected $fieldTypeNameableCollectionFactory; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | private $repositoryClass; |
||
51 | |||
52 | /** |
||
53 | * Collection of limitation types for the RoleService. |
||
54 | * |
||
55 | * @var \eZ\Publish\SPI\Limitation\Type[] |
||
56 | */ |
||
57 | protected $roleLimitations = array(); |
||
58 | |||
59 | /** |
||
60 | * @var array |
||
61 | */ |
||
62 | private $policyMap; |
||
63 | |||
64 | public function __construct( |
||
77 | |||
78 | /** |
||
79 | * Builds the main repository, heart of eZ Publish API. |
||
80 | * |
||
81 | * This always returns the true inner Repository, please depend on ezpublish.api.repository and not this method |
||
82 | * directly to make sure you get an instance wrapped inside Signal / Cache / * functionality. |
||
83 | * |
||
84 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
85 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
86 | * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer |
||
87 | * |
||
88 | * @return \eZ\Publish\API\Repository\Repository |
||
89 | */ |
||
90 | public function buildRepository( |
||
116 | |||
117 | /** |
||
118 | * Registers a limitation type for the RoleService. |
||
119 | * |
||
120 | * @param string $limitationName |
||
121 | * @param \eZ\Publish\SPI\Limitation\Type $limitationType |
||
122 | */ |
||
123 | public function registerLimitationType($limitationName, SPILimitationType $limitationType) |
||
127 | |||
128 | /** |
||
129 | * Returns a service based on a name string (content => contentService, etc). |
||
130 | * |
||
131 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
132 | * @param string $serviceName |
||
133 | * |
||
134 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException |
||
135 | * |
||
136 | * @return mixed |
||
137 | */ |
||
138 | View Code Duplication | public function buildService(Repository $repository, $serviceName) |
|
147 | } |
||
148 |