1 | <?php |
||
23 | class MediaIndexer |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var ResourceStorage |
||
28 | */ |
||
29 | protected $storage = null; |
||
30 | |||
31 | /** |
||
32 | * @param ResourceStorage $storage |
||
33 | */ |
||
34 | public function __construct(ResourceStorage $storage) |
||
38 | |||
39 | /** |
||
40 | * @param \TYPO3\CMS\Core\Resource\File $file |
||
41 | * @return $this |
||
42 | */ |
||
43 | public function updateIndex(File $file) |
||
48 | |||
49 | /** |
||
50 | * @param \TYPO3\CMS\Core\Resource\File $file |
||
51 | * @return $this |
||
52 | */ |
||
53 | public function extractMetadata(File $file) |
||
78 | |||
79 | /** |
||
80 | * @param \TYPO3\CMS\Core\Resource\File $file |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function applyDefaultCategories(File $file) |
||
105 | |||
106 | /** |
||
107 | * Retrieve the file metadata uid which is different from the file uid. |
||
108 | * |
||
109 | * @param \TYPO3\CMS\Core\Resource\File $file |
||
110 | * @return int |
||
111 | */ |
||
112 | protected function getFileMetadataIdentifier(File $file) |
||
117 | |||
118 | |||
119 | /** |
||
120 | * Returns an instance of the FileIndexRepository |
||
121 | * |
||
122 | * @return FileIndexRepository |
||
123 | */ |
||
124 | protected function getFileIndexRepository() |
||
128 | |||
129 | /** |
||
130 | * Returns an instance of the FileIndexRepository |
||
131 | * |
||
132 | * @return MetaDataRepository |
||
133 | */ |
||
134 | protected function getMetaDataRepository() |
||
138 | |||
139 | /** |
||
140 | * Returns an instance of the FileIndexRepository |
||
141 | * |
||
142 | * @return ExtractorRegistry |
||
143 | */ |
||
144 | protected function getExtractorRegistry() |
||
148 | |||
149 | /** |
||
150 | * @return object|DataService |
||
151 | */ |
||
152 | protected function getDataService(): DataService |
||
156 | |||
157 | /** |
||
158 | * @return \TYPO3\CMS\Core\Resource\Index\Indexer|object |
||
159 | */ |
||
160 | protected function getCoreIndexer() |
||
164 | |||
165 | } |
||
166 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.