Completed
Branch BUG-10381-asset-loading (4b39f3)
by
unknown
38:30 queued 26:21
created
core/services/collections/CollectionLoader.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -221,37 +221,37 @@
 block discarded – undo
221 221
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
222 222
 	 */
223 223
 	protected function setIdentifier( $entity, $identifier ) {
224
-	    switch($this->collection_details->identifierType()) {
225
-	        // every unique object gets added to the collection, but not duplicates of the exact same object
226
-            case CollectionDetails::ID_OBJECT_HASH :
227
-                $identifier = spl_object_hash($entity);
228
-                break;
229
-            // only one entity per class can be added to collection, like a singleton
230
-            case CollectionDetails::ID_CLASS_NAME :
231
-                $identifier = get_class($entity);
232
-                break;
233
-            // objects added to the collection based on entity callback, so the entity itself decides
234
-            case CollectionDetails::ID_CALLBACK_METHOD :
235
-                $identifier_callback = $this->collection_details->identifierCallback();
236
-                if ( ! method_exists($entity, $identifier_callback)) {
237
-                    throw new InvalidEntityException(
238
-                        $entity,
239
-                        $this->collection_details->getCollectionInterface(),
240
-                        sprintf(
241
-                            __(
242
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
224
+		switch($this->collection_details->identifierType()) {
225
+			// every unique object gets added to the collection, but not duplicates of the exact same object
226
+			case CollectionDetails::ID_OBJECT_HASH :
227
+				$identifier = spl_object_hash($entity);
228
+				break;
229
+			// only one entity per class can be added to collection, like a singleton
230
+			case CollectionDetails::ID_CLASS_NAME :
231
+				$identifier = get_class($entity);
232
+				break;
233
+			// objects added to the collection based on entity callback, so the entity itself decides
234
+			case CollectionDetails::ID_CALLBACK_METHOD :
235
+				$identifier_callback = $this->collection_details->identifierCallback();
236
+				if ( ! method_exists($entity, $identifier_callback)) {
237
+					throw new InvalidEntityException(
238
+						$entity,
239
+						$this->collection_details->getCollectionInterface(),
240
+						sprintf(
241
+							__(
242
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
243 243
                                 of "%2$s", but does not contain this method.',
244
-                                'event_espresso'
245
-                            ),
246
-                            $identifier_callback,
247
-                            get_class($entity)
248
-                        )
249
-                    );
250
-                }
251
-                $identifier = $entity->{$identifier_callback}();
252
-                break;
253
-
254
-        }
244
+								'event_espresso'
245
+							),
246
+							$identifier_callback,
247
+							get_class($entity)
248
+						)
249
+					);
250
+				}
251
+				$identifier = $entity->{$identifier_callback}();
252
+				break;
253
+
254
+		}
255 255
 		return apply_filters(
256 256
 			'FHEE__CollectionLoader__addEntityToCollection__identifier',
257 257
 			$identifier,
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\locators\LocatorInterface;
9 9
 use EventEspresso\core\services\locators\FileLocator;
10 10
 
11
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
12
-	exit( 'No direct script access allowed' );
11
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
12
+	exit('No direct script access allowed');
13 13
 }
14 14
 
15 15
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 		LocatorInterface $file_locator = null
82 82
 	) {
83 83
 		$this->collection_details = $collection_details;
84
-		if ( ! $collection instanceof CollectionInterface ) {
85
-			$collection = new Collection( $this->collection_details->getCollectionInterface() );
84
+		if ( ! $collection instanceof CollectionInterface) {
85
+			$collection = new Collection($this->collection_details->getCollectionInterface());
86 86
 		}
87 87
 		$this->collection = $collection;
88 88
 		$this->file_locator = $file_locator;
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
111 111
 	 */
112 112
 	protected function loadAllFromFilepaths() {
113
-		if ( ! $this->file_locator instanceof FileLocator ) {
113
+		if ( ! $this->file_locator instanceof FileLocator) {
114 114
 			$this->file_locator = new FileLocator();
115 115
 		}
116
-		$this->file_locator->setFileMask( $this->collection_details->getFileMask() );
116
+		$this->file_locator->setFileMask($this->collection_details->getFileMask());
117 117
 		// find all of the files that match the file mask in the specified folder
118
-		$this->file_locator->locate( $this->collection_details->getCollectionPaths() );
118
+		$this->file_locator->locate($this->collection_details->getCollectionPaths());
119 119
 		// filter the results
120 120
 		$filepaths = (array) apply_filters(
121 121
 			'FHEE__CollectionLoader__loadAllFromFilepath__filepaths',
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
 			$this->collection_details->collectionName(),
124 124
 			$this->collection_details
125 125
 		);
126
-		if ( empty( $filepaths ) ) {
126
+		if (empty($filepaths)) {
127 127
 			return;
128 128
 		}
129
-		foreach ( $filepaths as $filepath ) {
130
-			$this->loadClassFromFilepath( $filepath );
129
+		foreach ($filepaths as $filepath) {
130
+			$this->loadClassFromFilepath($filepath);
131 131
 		}
132 132
 	}
133 133
 
@@ -144,22 +144,22 @@  discard block
 block discarded – undo
144 144
 	 * @throws \EventEspresso\core\exceptions\InvalidFilePathException
145 145
 	 * @throws \EventEspresso\core\exceptions\InvalidClassException
146 146
 	 */
147
-	protected function loadClassFromFilepath( $filepath ) {
148
-		if ( ! is_string( $filepath ) ) {
149
-			throw new InvalidDataTypeException( '$filepath', $filepath, 'string' );
147
+	protected function loadClassFromFilepath($filepath) {
148
+		if ( ! is_string($filepath)) {
149
+			throw new InvalidDataTypeException('$filepath', $filepath, 'string');
150 150
 		}
151
-		if ( ! is_readable( $filepath ) ) {
152
-			throw new InvalidFilePathException( $filepath );
151
+		if ( ! is_readable($filepath)) {
152
+			throw new InvalidFilePathException($filepath);
153 153
 		}
154
-		require_once( $filepath );
154
+		require_once($filepath);
155 155
 		// extract filename from path
156
-		$file_name = basename( $filepath );
156
+		$file_name = basename($filepath);
157 157
 		// now remove any file extensions
158
-		$class_name = \EEH_File::get_classname_from_filepath_with_standard_filename( $file_name );
159
-		if ( ! class_exists( $class_name ) ) {
160
-			throw new InvalidClassException( $class_name );
158
+		$class_name = \EEH_File::get_classname_from_filepath_with_standard_filename($file_name);
159
+		if ( ! class_exists($class_name)) {
160
+			throw new InvalidClassException($class_name);
161 161
 		}
162
-		return $this->addEntityToCollection( new $class_name(), $file_name );
162
+		return $this->addEntityToCollection(new $class_name(), $file_name);
163 163
 	}
164 164
 
165 165
 
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
 	 * @return string
174 174
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
175 175
 	 */
176
-	protected function addEntityToCollection( $entity, $identifier ) {
176
+	protected function addEntityToCollection($entity, $identifier) {
177 177
 		do_action(
178 178
 			'FHEE__CollectionLoader__addEntityToCollection__entity',
179 179
 			$entity,
180 180
 			$this->collection_details->collectionName(),
181 181
 			$this->collection_details
182 182
 		);
183
-		$identifier = $this->setIdentifier( $entity, $identifier );
184
-		if ( $this->collection->has( $identifier ) ) {
183
+		$identifier = $this->setIdentifier($entity, $identifier);
184
+		if ($this->collection->has($identifier)) {
185 185
 			do_action(
186 186
 				'FHEE__CollectionLoader__addEntityToCollection__entity_already_added',
187 187
 				$this,
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 			);
191 191
 			return CollectionLoader::ENTITY_EXISTS;
192 192
 		}
193
-		if( $this->collection->add( $entity, $identifier ) ) {
193
+		if ($this->collection->add($entity, $identifier)) {
194 194
 			do_action(
195 195
 				'FHEE__CollectionLoader__addEntityToCollection__entity_added',
196 196
 				$this,
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 	 * @return string
221 221
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
222 222
 	 */
223
-	protected function setIdentifier( $entity, $identifier ) {
224
-	    switch($this->collection_details->identifierType()) {
223
+	protected function setIdentifier($entity, $identifier) {
224
+	    switch ($this->collection_details->identifierType()) {
225 225
 	        // every unique object gets added to the collection, but not duplicates of the exact same object
226 226
             case CollectionDetails::ID_OBJECT_HASH :
227 227
                 $identifier = spl_object_hash($entity);
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
 			$this->collection_details->collectionName(),
279 279
 			$this->collection_details
280 280
 		);
281
-		foreach ( $FQCNs as $FQCN ) {
282
-			$this->loadClassFromFQCN( $FQCN );
281
+		foreach ($FQCNs as $FQCN) {
282
+			$this->loadClassFromFQCN($FQCN);
283 283
 		}
284 284
 	}
285 285
 
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
 	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
296 296
 	 * @throws \EventEspresso\core\exceptions\InvalidClassException
297 297
 	 */
298
-	protected function loadClassFromFQCN( $FQCN ) {
299
-		if ( ! is_string( $FQCN ) ) {
300
-			throw new InvalidDataTypeException( '$FQCN', $FQCN, 'string' );
298
+	protected function loadClassFromFQCN($FQCN) {
299
+		if ( ! is_string($FQCN)) {
300
+			throw new InvalidDataTypeException('$FQCN', $FQCN, 'string');
301 301
 		}
302
-		if ( ! class_exists( $FQCN ) ) {
303
-			throw new InvalidClassException( $FQCN );
302
+		if ( ! class_exists($FQCN)) {
303
+			throw new InvalidClassException($FQCN);
304 304
 		}
305 305
 		return $this->addEntityToCollection(
306
-			\EE_Registry::instance()->create( $FQCN ),
306
+			\EE_Registry::instance()->create($FQCN),
307 307
 			$FQCN
308 308
 		);
309 309
 	}
Please login to merge, or discard this patch.