@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * @param $key |
| 176 | - * @return IMusicService|null |
|
| 176 | + * @return BaseService|null |
|
| 177 | 177 | */ |
| 178 | 178 | public function getService($key) |
| 179 | 179 | { |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
| 218 | - * @return IMusicService |
|
| 218 | + * @return BaseService|null |
|
| 219 | 219 | */ |
| 220 | 220 | public function getPreferredService() |
| 221 | 221 | { |
@@ -8,7 +8,6 @@ |
||
| 8 | 8 | use Pbxg33k\MusicInfo\Model\IMusicService; |
| 9 | 9 | use Pbxg33k\MusicInfo\Service\BaseService; |
| 10 | 10 | use Pbxg33k\Traits\PropertyTrait; |
| 11 | -use Symfony\Component\Config\FileLocator; |
|
| 12 | 11 | |
| 13 | 12 | class MusicInfo |
| 14 | 13 | { |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | new Client($config['defaults']['guzzle']) |
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | - if(isset($config['services'])) { |
|
| 52 | - foreach($config['services'] as $service) { |
|
| 53 | - if(!isset($config['init_services'])) { |
|
| 51 | + if (isset($config['services'])) { |
|
| 52 | + foreach ($config['services'] as $service) { |
|
| 53 | + if (!isset($config['init_services'])) { |
|
| 54 | 54 | $config['init_services'] = null; |
| 55 | 55 | } |
| 56 | 56 | $this->loadService($service, $config['init_services']); |
@@ -93,19 +93,19 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function loadService($service, $init = false) |
| 95 | 95 | { |
| 96 | - $fqcn = implode('\\',['Pbxg33k', 'MusicInfo', 'Service', $service, 'Service']); |
|
| 97 | - if(class_exists($fqcn)) { |
|
| 96 | + $fqcn = implode('\\', ['Pbxg33k', 'MusicInfo', 'Service', $service, 'Service']); |
|
| 97 | + if (class_exists($fqcn)) { |
|
| 98 | 98 | /** @var IMusicService $client */ |
| 99 | 99 | $client = new $fqcn(); |
| 100 | 100 | $client->setConfig($this->mergeConfig($service)); |
| 101 | 101 | $client->setClient($this->getClient()); |
| 102 | - if($init == true) { |
|
| 102 | + if ($init == true) { |
|
| 103 | 103 | $client->init(); |
| 104 | 104 | } |
| 105 | 105 | $this->addService($client, $service); |
| 106 | 106 | return $service; |
| 107 | 107 | } else { |
| 108 | - throw new \Exception('Service class does not exist: '.$service.' ('.$fqcn.')'); |
|
| 108 | + throw new \Exception('Service class does not exist: ' . $service . ' (' . $fqcn . ')'); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function mergeConfig($service) |
| 119 | 119 | { |
| 120 | 120 | $service = strtolower($service); |
| 121 | - if(isset($this->config['service_configuration'][$service])) { |
|
| 121 | + if (isset($this->config['service_configuration'][$service])) { |
|
| 122 | 122 | $config = array_merge( |
| 123 | 123 | $this->config['defaults'], |
| 124 | 124 | $this->config['service_configuration'][$service] |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function loadServices($initialize = false) |
| 141 | 141 | { |
| 142 | - foreach($this->supportedServices as $service) { |
|
| 142 | + foreach ($this->supportedServices as $service) { |
|
| 143 | 143 | $this->loadService($service, $initialize); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | public function getService($key) |
| 173 | 173 | { |
| 174 | 174 | $key = strtolower($key); |
| 175 | - if(isset($this->services[$key])) { |
|
| 175 | + if (isset($this->services[$key])) { |
|
| 176 | 176 | return $this->initializeService($this->services[$key]); |
| 177 | 177 | } else { |
| 178 | 178 | return null; |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function initializeService(BaseService $service) |
| 189 | 189 | { |
| 190 | - if(!$service->isInitialized()) { |
|
| 190 | + if (!$service->isInitialized()) { |
|
| 191 | 191 | $service->init(); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function removeService($key) |
| 203 | 203 | { |
| 204 | - if(isset($this->services[$key])) { |
|
| 204 | + if (isset($this->services[$key])) { |
|
| 205 | 205 | unset($this->services[$key]); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -229,26 +229,26 @@ discard block |
||
| 229 | 229 | public function doSearch($argument, $type, $servicesArg = null) |
| 230 | 230 | { |
| 231 | 231 | $services = []; |
| 232 | - if(null === $servicesArg) { |
|
| 232 | + if (null === $servicesArg) { |
|
| 233 | 233 | $services = $this->getServices(); |
| 234 | - } elseif(is_array($servicesArg)) { |
|
| 235 | - foreach($servicesArg as $service) { |
|
| 236 | - if(is_string($service) && $loadedService = $this->getService($service)) { |
|
| 234 | + } elseif (is_array($servicesArg)) { |
|
| 235 | + foreach ($servicesArg as $service) { |
|
| 236 | + if (is_string($service) && $loadedService = $this->getService($service)) { |
|
| 237 | 237 | $services[$service] = $loadedService; |
| 238 | 238 | } else { |
| 239 | 239 | throw new \Exception(sprintf('Service (%s) cannot be found', $service)); |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - } elseif(is_string($servicesArg) && $loadedService = $this->getService($servicesArg)) { |
|
| 242 | + } elseif (is_string($servicesArg) && $loadedService = $this->getService($servicesArg)) { |
|
| 243 | 243 | $services[$servicesArg] = $loadedService; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | $results = []; |
| 247 | 247 | |
| 248 | - foreach($services as $serviceKey => $service) { |
|
| 248 | + foreach ($services as $serviceKey => $service) { |
|
| 249 | 249 | $methodName = $this->getMethodName($type); |
| 250 | 250 | |
| 251 | - if(!method_exists($service, $methodName)) { |
|
| 251 | + if (!method_exists($service, $methodName)) { |
|
| 252 | 252 | throw new \Exception(sprintf('Method (%s) not found in %s', $methodName, get_class($service))); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -2,9 +2,7 @@ |
||
| 2 | 2 | namespace Pbxg33k\MusicInfo\DependencyInjection; |
| 3 | 3 | |
| 4 | 4 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
| 5 | -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
| 6 | 5 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 7 | -use Symfony\Component\Config\FileLocator; |
|
| 8 | 6 | |
| 9 | 7 | class MusicInfoExtension extends Extension |
| 10 | 8 | { |
@@ -127,8 +127,8 @@ |
||
| 127 | 127 | public function transformCollection($raw) |
| 128 | 128 | { |
| 129 | 129 | $collection = new ArrayCollection(); |
| 130 | - if(is_object($raw) && isset($raw->artists)) { |
|
| 131 | - foreach($raw->artists->items as $artist) { |
|
| 130 | + if (is_object($raw) && isset($raw->artists)) { |
|
| 131 | + foreach ($raw->artists->items as $artist) { |
|
| 132 | 132 | $collection->add($this->transformSingle($artist)); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | public function transformCollection($raw) |
| 78 | 78 | { |
| 79 | 79 | $collection = new ArrayCollection(); |
| 80 | - foreach($raw->collection as $artist) |
|
| 80 | + foreach ($raw->collection as $artist) |
|
| 81 | 81 | { |
| 82 | 82 | $collection->add($this->transformSingle($artist)); |
| 83 | 83 | } |
@@ -77,8 +77,7 @@ |
||
| 77 | 77 | public function transformCollection($raw) |
| 78 | 78 | { |
| 79 | 79 | $collection = new ArrayCollection(); |
| 80 | - foreach($raw->collection as $artist) |
|
| 81 | - { |
|
| 80 | + foreach($raw->collection as $artist) { |
|
| 82 | 81 | $collection->add($this->transformSingle($artist)); |
| 83 | 82 | } |
| 84 | 83 | |