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 |
||
22 | class RepositoryFactory implements ContainerAwareInterface |
||
23 | { |
||
24 | use ContainerAwareTrait; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $repositoryClass; |
||
30 | |||
31 | /** |
||
32 | * Collection of fieldTypes, lazy loaded via a closure. |
||
33 | * |
||
34 | * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeCollectionFactory |
||
35 | */ |
||
36 | protected $fieldTypeCollectionFactory; |
||
37 | |||
38 | /** |
||
39 | * Collection of fieldTypes, lazy loaded via a closure. |
||
40 | * |
||
41 | * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeNameableCollectionFactory |
||
42 | */ |
||
43 | protected $fieldTypeNameableCollectionFactory; |
||
44 | |||
45 | /** |
||
46 | * Collection of limitation types for the RoleService. |
||
47 | * |
||
48 | * @var \eZ\Publish\SPI\Limitation\Type[] |
||
49 | */ |
||
50 | protected $roleLimitations = array(); |
||
51 | |||
52 | /** |
||
53 | * Policies map. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $policyMap = array(); |
||
58 | |||
59 | View Code Duplication | public function __construct( |
|
70 | |||
71 | /** |
||
72 | * Builds the main repository, heart of eZ Publish API. |
||
73 | * |
||
74 | * This always returns the true inner Repository, please depend on ezpublish.api.repository and not this method |
||
75 | * directly to make sure you get an instance wrapped inside Signal / Cache / * functionality. |
||
76 | * |
||
77 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
78 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
79 | * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer |
||
80 | * |
||
81 | * @return \eZ\Publish\API\Repository\Repository |
||
82 | */ |
||
83 | public function buildRepository( |
||
108 | |||
109 | /** |
||
110 | * Registers a limitation type for the RoleService. |
||
111 | * |
||
112 | * @param string $limitationName |
||
113 | * @param \eZ\Publish\SPI\Limitation\Type $limitationType |
||
114 | */ |
||
115 | public function registerLimitationType($limitationName, SPILimitationType $limitationType) |
||
119 | |||
120 | /** |
||
121 | * Returns a service based on a name string (content => contentService, etc). |
||
122 | * |
||
123 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
124 | * @param string $serviceName |
||
125 | * |
||
126 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException |
||
127 | * |
||
128 | * @return mixed |
||
129 | */ |
||
130 | public function buildService(Repository $repository, $serviceName) |
||
139 | } |
||
140 |