Completed
Pull Request — develop (#1272)
by
unknown
45s
created
src/SWP/Bundle/ContentBundle/Routing/SeoMediaRouter.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,6 +50,6 @@
 block discarded – undo
50 50
       unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
51 51
     }
52 52
 
53
-    return 'Route for media ' . $name->getValues()->getId() . ' not found';
53
+    return 'Route for media '.$name->getValues()->getId().' not found';
54 54
   }
55 55
 }
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
 
27 27
 class SeoMediaRouter extends Router implements VersatileGeneratorInterface {
28 28
 
29
-  const OBJECT_BASED_ROUTE_NAME = "__seo_media_router_route_name__";
29
+    const OBJECT_BASED_ROUTE_NAME = "__seo_media_router_route_name__";
30 30
 
31
-  /**
32
-   * {@inheritdoc}
33
-   */
34
-  public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) {
31
+    /**
32
+     * {@inheritdoc}
33
+     */
34
+    public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) {
35 35
     if (self::OBJECT_BASED_ROUTE_NAME === $name && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) {
36
-      $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
37
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
36
+        $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
37
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
38 38
     }
39 39
 
40 40
     $item = $name->getValues()->getImage();
@@ -43,18 +43,18 @@  discard block
 block discarded – undo
43 43
     $parameters['extension'] = $item->getFileExtension();
44 44
 
45 45
     return parent::generate('swp_seo_media_get', $parameters, $referenceType);
46
-  }
46
+    }
47 47
 
48
-  public function supports($name): bool {
48
+    public function supports($name): bool {
49 49
     return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || ($name instanceof Meta && $name->getValues() instanceof ArticleSeoMediaInterface);
50
-  }
50
+    }
51 51
 
52
-  public function getRouteDebugMessage($name, array $parameters = array()): string {
52
+    public function getRouteDebugMessage($name, array $parameters = array()): string {
53 53
     if (self::OBJECT_BASED_ROUTE_NAME === $name && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) {
54
-      $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
55
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
54
+        $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
55
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
56 56
     }
57 57
 
58 58
     return 'Route for media ' . $name->getValues()->getId() . ' not found';
59
-  }
59
+    }
60 60
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Twig/DecoratingRoutingExtension.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
     try {
46 46
       return $this->routingExtension->getPath($name, $parameters, $relative);
47
-    } catch (RouteNotFoundException|MissingMandatoryParametersException|InvalidParameterException $e) {
47
+    } catch (RouteNotFoundException | MissingMandatoryParametersException | InvalidParameterException $e) {
48 48
       // allow empty path
49 49
     }
50 50
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
     try {
66 66
       return $this->routingExtension->getUrl($name, $parameters, $schemeRelative);
67
-    } catch (RouteNotFoundException|MissingMandatoryParametersException|InvalidParameterException $e) {
67
+    } catch (RouteNotFoundException | MissingMandatoryParametersException | InvalidParameterException $e) {
68 68
       // allow empty url
69 69
     }
70 70
 
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -36,88 +36,88 @@
 block discarded – undo
36 36
 use Twig\TwigFunction;
37 37
 
38 38
 final class DecoratingRoutingExtension extends AbstractExtension {
39
-  private RoutingExtension $routingExtension;
39
+    private RoutingExtension $routingExtension;
40 40
 
41
-  public function __construct(RoutingExtension $routingExtension) {
41
+    public function __construct(RoutingExtension $routingExtension) {
42 42
     $this->routingExtension = $routingExtension;
43
-  }
43
+    }
44 44
 
45
-  public function getPath($name, $parameters = [], $relative = false): ?string {
45
+    public function getPath($name, $parameters = [], $relative = false): ?string {
46 46
     if ($name == null) {
47
-      return null;
47
+        return null;
48 48
     }
49 49
 
50 50
     if (is_object($name)) {
51
-      $object = $name;
52
-      $name = null;
53
-      self::setupParams($object, $name, $parameters);
51
+        $object = $name;
52
+        $name = null;
53
+        self::setupParams($object, $name, $parameters);
54 54
     }
55 55
 
56 56
     try {
57
-      return $this->routingExtension->getPath($name, $parameters, $relative);
57
+        return $this->routingExtension->getPath($name, $parameters, $relative);
58 58
     } catch (RouteNotFoundException|MissingMandatoryParametersException|InvalidParameterException $e) {
59
-      // allow empty path
59
+        // allow empty path
60 60
     }
61 61
 
62 62
     return null;
63
-  }
63
+    }
64 64
 
65
-  public function getUrl($name, $parameters = [], $schemeRelative = false): ?string {
65
+    public function getUrl($name, $parameters = [], $schemeRelative = false): ?string {
66 66
     if ($name == null) {
67
-      return null;
67
+        return null;
68 68
     }
69 69
 
70 70
     if (is_object($name)) {
71
-      $object = $name;
72
-      $name = null;
73
-      self::setupParams($object, $name, $parameters);
71
+        $object = $name;
72
+        $name = null;
73
+        self::setupParams($object, $name, $parameters);
74 74
     }
75 75
 
76 76
     try {
77
-      return $this->routingExtension->getUrl($name, $parameters, $schemeRelative);
77
+        return $this->routingExtension->getUrl($name, $parameters, $schemeRelative);
78 78
     } catch (RouteNotFoundException|MissingMandatoryParametersException|InvalidParameterException $e) {
79
-      // allow empty url
79
+        // allow empty url
80 80
     }
81 81
 
82 82
     return null;
83
-  }
83
+    }
84 84
 
85
-  public static function setupParams(object $object, &$name, &$parameters) {
85
+    public static function setupParams(object $object, &$name, &$parameters) {
86 86
     $name = RouteObjectInterface::OBJECT_BASED_ROUTE_NAME;
87 87
     $parameters[RouteObjectInterface::ROUTE_OBJECT] = $object;
88 88
 
89 89
     if ($object instanceof Meta) {
90
-      $values = $object->getValues();
91
-      if (($values instanceof ArticleMediaInterface || $values instanceof ImageRenditionInterface)) {
90
+        $values = $object->getValues();
91
+        if (($values instanceof ArticleMediaInterface || $values instanceof ImageRenditionInterface)) {
92 92
         $name = MediaRouter::OBJECT_BASED_ROUTE_NAME;
93 93
         return;
94
-      }
94
+        }
95 95
 
96
-      if ($values instanceof ArticleSeoMediaInterface) {
96
+        if ($values instanceof ArticleSeoMediaInterface) {
97 97
         $name = SeoMediaRouter::OBJECT_BASED_ROUTE_NAME;
98 98
         return;
99
-      }
99
+        }
100 100
 
101
-      if ($values instanceof AuthorMediaInterface) {
101
+        if ($values instanceof AuthorMediaInterface) {
102 102
         $name = ArticleAuthorMediaRouter::OBJECT_BASED_ROUTE_NAME;
103 103
         return;
104
-      }
104
+        }
105 105
 
106
-      if ($values instanceof ArticleInterface || $values instanceof RouteInterface) {
106
+        if ($values instanceof ArticleInterface || $values instanceof RouteInterface) {
107 107
         $name = MetaRouter::OBJECT_BASED_ROUTE_NAME;
108 108
         return;
109
-      }
109
+        }
110 110
     }
111 111
 
112 112
     if ($object instanceof RouteInterface || $object instanceof ArticleInterface) {
113
-      $name = MetaRouter::OBJECT_BASED_ROUTE_NAME;
113
+        $name = MetaRouter::OBJECT_BASED_ROUTE_NAME;
114
+    }
114 115
     }
115
-  }
116 116
 
117
-  public function getFunctions(): array {
117
+    public function getFunctions(): array {
118 118
     return [
119 119
         new TwigFunction('url', [$this, 'getUrl'], ['is_safe_callback' => [$this->routingExtension, 'isUrlGenerationSafe']]),
120 120
         new TwigFunction('path', [$this, 'getPath'], ['is_safe_callback' => [$this->routingExtension, 'isUrlGenerationSafe']]),
121 121
     ];
122
-  }
122
+    }
123 123
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Routing/MetaRouter.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
       $name = $route->getId();
84 84
     }
85 85
 
86
-    return md5($name . serialize($parameters) . $type);
86
+    return md5($name.serialize($parameters).$type);
87 87
   }
88 88
 
89 89
   /**
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -24,43 +24,43 @@  discard block
 block discarded – undo
24 24
 use Symfony\Component\Routing\Route as SymfonyRoute;
25 25
 
26 26
 class MetaRouter extends DynamicRouter {
27
-  const OBJECT_BASED_ROUTE_NAME = "__meta_router_route_name__";
27
+    const OBJECT_BASED_ROUTE_NAME = "__meta_router_route_name__";
28 28
 
29
-  protected $internalRoutesCache = [];
29
+    protected $internalRoutesCache = [];
30 30
 
31
-  public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) {
31
+    public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) {
32 32
     if (self::OBJECT_BASED_ROUTE_NAME === $name
33 33
         && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)
34 34
     ) {
35
-      $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
36
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
35
+        $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
36
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
37 37
     }
38 38
 
39 39
     $cacheKey = $this->getCacheKey($name, $parameters, $referenceType);
40 40
     if (array_key_exists($cacheKey, $this->internalRoutesCache)) {
41
-      return $this->internalRoutesCache[$cacheKey];
41
+        return $this->internalRoutesCache[$cacheKey];
42 42
     }
43 43
 
44 44
     $route = $name;
45 45
     if ($name instanceof Meta) {
46
-      $object = $name->getValues();
47
-      if ($object instanceof ArticleInterface) {
46
+        $object = $name->getValues();
47
+        if ($object instanceof ArticleInterface) {
48 48
         $parameters['slug'] = $object->getSlug();
49 49
         $route = $object->getRoute();
50 50
         if (null === $route && $name->getContext()->getCurrentPage()) {
51
-          $parameters['slug'] = null;
52
-          $route = $name->getContext()->getCurrentPage()->getValues();
51
+            $parameters['slug'] = null;
52
+            $route = $name->getContext()->getCurrentPage()->getValues();
53 53
         }
54
-      } elseif ($name->getValues() instanceof RouteInterface) {
54
+        } elseif ($name->getValues() instanceof RouteInterface) {
55 55
         $route = $name->getValues();
56
-      }
56
+        }
57 57
     } elseif ($name instanceof ArticleInterface) {
58
-      $route = $name->getRoute();
59
-      $parameters['slug'] = $name->getSlug();
58
+        $route = $name->getRoute();
59
+        $parameters['slug'] = $name->getSlug();
60 60
     }
61 61
 
62 62
     if (null === $route || is_array($route)) {
63
-      throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
63
+        throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
64 64
     }
65 65
 
66 66
     $result = parent::generate($route, $parameters, $referenceType);
@@ -68,29 +68,29 @@  discard block
 block discarded – undo
68 68
     unset($route);
69 69
 
70 70
     return $result;
71
-  }
71
+    }
72 72
 
73
-  private function getCacheKey($route, $parameters, $type) {
73
+    private function getCacheKey($route, $parameters, $type) {
74 74
     $name = $route;
75 75
     if ($route instanceof Meta) {
76
-      if ($route->getValues() instanceof ArticleInterface) {
76
+        if ($route->getValues() instanceof ArticleInterface) {
77 77
         $name = $route->getValues()->getId();
78
-      } elseif ($route->getValues() instanceof RouteInterface) {
78
+        } elseif ($route->getValues() instanceof RouteInterface) {
79 79
         $name = $route->getValues()->getName();
80
-      }
80
+        }
81 81
     } elseif ($route instanceof RouteInterface) {
82
-      $name = $route->getName();
82
+        $name = $route->getName();
83 83
     } elseif ($route instanceof ArticleInterface) {
84
-      $name = $route->getId();
84
+        $name = $route->getId();
85 85
     }
86 86
 
87 87
     return md5($name . serialize($parameters) . $type);
88
-  }
88
+    }
89 89
 
90
-  /**
91
-   * {@inheritdoc}
92
-   */
93
-  public function supports($name) {
90
+    /**
91
+     * {@inheritdoc}
92
+     */
93
+    public function supports($name) {
94 94
     return
95 95
         ($name instanceof Meta && (
96 96
                 $name->getValues() instanceof ArticleInterface ||
@@ -106,5 +106,5 @@  discard block
 block discarded – undo
106 106
             'swp_media_get' !== $name &&
107 107
             false === strpos($name, 'swp_api_')
108 108
         );
109
-  }
109
+    }
110 110
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Command/ProcessPackagesCommand.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -123,8 +123,8 @@
 block discarded – undo
123 123
         /** @var SlidingPagination $pagination */
124 124
         $pagination = $this->paginator->paginate(
125 125
             $queryBuilder,
126
-            (int)  $input->getOption('page'),
127
-            (int)  $input->getOption('limit')
126
+            (int) $input->getOption('page'),
127
+            (int) $input->getOption('limit')
128 128
         );
129 129
 
130 130
         $output->writeln(sprintf('<bg=green;options=bold>Packages found: %s</>', $pagination->getTotalItemCount()));
Please login to merge, or discard this patch.
src/SWP/Bundle/MultiTenancyBundle/Routing/TenantAwareRouter.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@
 block discarded – undo
31 31
      */
32 32
     public function generate($name, $parameters = [], $referenceType = false)
33 33
     {
34
-      if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name
34
+        if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name
35 35
           && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)
36
-      ) {
36
+        ) {
37 37
         $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
38 38
         unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
39
-      }
39
+        }
40 40
 
41 41
         if (null === $name && isset($parameters['content_id'])) {
42 42
             $contentId = $this->checkAndRemoveFirstSlash($parameters['content_id']);
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Routing/ArticleAuthorMediaRouter.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,6 +71,6 @@
 block discarded – undo
71 71
       $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
72 72
       unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
73 73
     }
74
-    return 'Route for article author media ' . $name->getValues()->getId() . ' not found';
74
+    return 'Route for article author media '.$name->getValues()->getId().' not found';
75 75
   }
76 76
 }
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -27,53 +27,53 @@
 block discarded – undo
27 27
 
28 28
 class ArticleAuthorMediaRouter extends Router implements VersatileGeneratorInterface {
29 29
 
30
-  const OBJECT_BASED_ROUTE_NAME = "__article_author_media_router_route_name__";
30
+    const OBJECT_BASED_ROUTE_NAME = "__article_author_media_router_route_name__";
31 31
 
32
-  protected $authorMediaManager;
32
+    protected $authorMediaManager;
33 33
 
34
-  public function __construct(
35
-      ContainerInterface $container,
36
-                         $resource,
37
-      array              $options = [],
38
-      RequestContext     $context = null,
39
-      ContainerInterface $parameters = null,
40
-      LoggerInterface    $logger = null,
41
-      string             $defaultLocale = null
42
-  ) {
34
+    public function __construct(
35
+        ContainerInterface $container,
36
+                            $resource,
37
+        array              $options = [],
38
+        RequestContext     $context = null,
39
+        ContainerInterface $parameters = null,
40
+        LoggerInterface    $logger = null,
41
+        string             $defaultLocale = null
42
+    ) {
43 43
     $this->authorMediaManager = $container->get('swp_core_bundle.manager.author_media');
44 44
 
45 45
     parent::__construct($container, $resource, $options, $context, $parameters, $logger, $defaultLocale);
46
-  }
46
+    }
47 47
 
48
-  public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) {
48
+    public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) {
49 49
     if (self::OBJECT_BASED_ROUTE_NAME === $meta
50 50
         && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)
51 51
     ) {
52
-      $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
53
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
52
+        $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
53
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
54 54
     }
55 55
 
56 56
     if ($meta instanceof Meta && ($meta->getValues() instanceof AuthorMediaInterface)) {
57
-      return $this->authorMediaManager->getMediaPublicUrl($meta->getValues()->getImage());
57
+        return $this->authorMediaManager->getMediaPublicUrl($meta->getValues()->getImage());
58 58
     }
59 59
 
60 60
     return '';
61
-  }
61
+    }
62 62
 
63
-  /**
64
-   * {@inheritdoc}
65
-   */
66
-  public function supports($name) {
63
+    /**
64
+     * {@inheritdoc}
65
+     */
66
+    public function supports($name) {
67 67
     return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) || ($name instanceof Meta && ($name->getValues() instanceof AuthorMediaInterface));
68
-  }
68
+    }
69 69
 
70
-  public function getRouteDebugMessage($name, array $parameters = []) {
70
+    public function getRouteDebugMessage($name, array $parameters = []) {
71 71
     if (self::OBJECT_BASED_ROUTE_NAME === $name
72 72
         && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)
73 73
     ) {
74
-      $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
75
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
74
+        $name = $parameters[RouteObjectInterface::ROUTE_OBJECT];
75
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
76 76
     }
77 77
     return 'Route for article author media ' . $name->getValues()->getId() . ' not found';
78
-  }
78
+    }
79 79
 }
Please login to merge, or discard this patch.
src/SWP/Component/MultiTenancy/Exception/TenantNotFoundException.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
18 18
 
19 19
 class TenantNotFoundException extends NotFoundHttpException {
20
-  public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) {
20
+    public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) {
21 21
     parent::__construct(sprintf('Tenant for host "%s" could not be found! Please check tenants configuration.', $message), $previous, $code, $headers);
22
-  }
22
+    }
23 23
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/ContentBundle/Routing/MediaRouter.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -31,82 +31,82 @@  discard block
 block discarded – undo
31 31
 use Symfony\Component\Routing\RequestContext;
32 32
 
33 33
 class MediaRouter extends Router implements VersatileGeneratorInterface {
34
-  private $mediaManager;
35
-
36
-  const OBJECT_BASED_ROUTE_NAME = "__media_router_route_name__";
37
-
38
-  public function __construct(
39
-      ContainerInterface $container,
40
-                         $resource,
41
-      array              $options = [],
42
-      RequestContext     $context = null,
43
-      ContainerInterface $parameters = null,
44
-      LoggerInterface    $logger = null,
45
-      string             $defaultLocale = null
46
-  ) {
34
+    private $mediaManager;
35
+
36
+    const OBJECT_BASED_ROUTE_NAME = "__media_router_route_name__";
37
+
38
+    public function __construct(
39
+        ContainerInterface $container,
40
+                            $resource,
41
+        array              $options = [],
42
+        RequestContext     $context = null,
43
+        ContainerInterface $parameters = null,
44
+        LoggerInterface    $logger = null,
45
+        string             $defaultLocale = null
46
+    ) {
47 47
     $this->mediaManager = $container->get('swp_content_bundle.manager.media');
48 48
 
49 49
     parent::__construct($container, $resource, $options, $context, $parameters, $logger, $defaultLocale);
50
-  }
50
+    }
51 51
 
52
-  public function getRouteDebugMessage($meta, array $parameters = array()): string {
52
+    public function getRouteDebugMessage($meta, array $parameters = array()): string {
53 53
     if (self::OBJECT_BASED_ROUTE_NAME === $meta && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) {
54
-      $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
55
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
54
+        $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
55
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
56 56
     }
57 57
     return 'Route for media ' . $meta->getValues()->getId() . ' not found';
58
-  }
58
+    }
59 59
 
60
-  public function supports($name): bool {
60
+    public function supports($name): bool {
61 61
     return (is_string($name) && $name == self::OBJECT_BASED_ROUTE_NAME) ||
62 62
         ($name instanceof Meta && (
63 63
                 $name->getValues() instanceof ArticleMediaInterface ||
64 64
                 $name->getValues() instanceof ImageRenditionInterface));
65
-  }
65
+    }
66 66
 
67
-  public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string {
67
+    public function generate($meta, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string {
68 68
     if (self::OBJECT_BASED_ROUTE_NAME === $meta && array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)) {
69
-      $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
70
-      unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
69
+        $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
70
+        unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
71 71
     }
72 72
 
73 73
     if (!$meta instanceof Meta) {
74
-      return '';
74
+        return '';
75 75
     }
76 76
 
77 77
     $item = $this->getItem($meta);
78 78
     if (null === $item) {
79
-      return '';
79
+        return '';
80 80
     }
81 81
 
82 82
     if ($meta->getValues() instanceof ImageRenditionInterface && null !== ($previewUrl = $meta->getValues()->getPreviewUrl())) {
83
-      return $previewUrl;
83
+        return $previewUrl;
84 84
     }
85 85
 
86 86
     if ($item instanceof PreviewUrlAwareInterface && null !== ($previewUrl = $item->getPreviewUrl())) {
87
-      return $previewUrl;
87
+        return $previewUrl;
88 88
     }
89 89
 
90 90
     return $this->getUrlWithCorrectExtension($item, $parameters);
91
-  }
91
+    }
92 92
 
93
-  private function getItem(Meta $meta): ?FileInterface {
93
+    private function getItem(Meta $meta): ?FileInterface {
94 94
     if (($rendition = $meta->getValues()) instanceof ImageRendition) {
95
-      return $rendition->getImage();
95
+        return $rendition->getImage();
96 96
     }
97 97
 
98 98
     if (($image = $meta->getValues()->getImage()) instanceof ImageInterface) {
99
-      return $image;
99
+        return $image;
100 100
     }
101 101
 
102 102
     if (($file = $meta->getValues()->getFile()) instanceof FileInterface) {
103
-      return $file;
103
+        return $file;
104 104
     }
105 105
 
106 106
     return null;
107
-  }
107
+    }
108 108
 
109
-  private function getUrlWithCorrectExtension(FileInterface $item, array $parameters): string {
109
+    private function getUrlWithCorrectExtension(FileInterface $item, array $parameters): string {
110 110
     $url = $this->mediaManager->getMediaPublicUrl($item);
111 111
 
112 112
     if (
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
         true === $parameters['webp'] &&
116 116
         $item->hasVariant(ImageInterface::VARIANT_WEBP)
117 117
     ) {
118
-      return str_replace('.' . $item->getFileExtension(), '.webp', $url);
118
+        return str_replace('.' . $item->getFileExtension(), '.webp', $url);
119 119
     }
120 120
 
121 121
     return $url;
122
-  }
122
+    }
123 123
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
       $meta = $parameters[RouteObjectInterface::ROUTE_OBJECT];
55 55
       unset($parameters[RouteObjectInterface::ROUTE_OBJECT]);
56 56
     }
57
-    return 'Route for media ' . $meta->getValues()->getId() . ' not found';
57
+    return 'Route for media '.$meta->getValues()->getId().' not found';
58 58
   }
59 59
 
60 60
   public function supports($name): bool {
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         true === $parameters['webp'] &&
116 116
         $item->hasVariant(ImageInterface::VARIANT_WEBP)
117 117
     ) {
118
-      return str_replace('.' . $item->getFileExtension(), '.webp', $url);
118
+      return str_replace('.'.$item->getFileExtension(), '.webp', $url);
119 119
     }
120 120
 
121 121
     return $url;
Please login to merge, or discard this patch.
SWP/Bundle/CoreBundle/EventListener/DownloadArticleAuthorAvatarListener.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -34,87 +34,87 @@  discard block
 block discarded – undo
34 34
 use SWP\Component\Common\Exception\UnexpectedTypeException;
35 35
 
36 36
 final class DownloadArticleAuthorAvatarListener {
37
-  /**
38
-   * @var MediaManagerInterface
39
-   */
40
-  private $authorMediaManager;
41
-
42
-  /**
43
-   * @var EntityManagerInterface
44
-   */
45
-  private $entityManager;
46
-
47
-  /**
48
-   * @var string
49
-   */
50
-  private $cacheDirectory;
51
-
52
-  public function __construct(EntityManagerInterface $entityManager, $cacheDirectory) {
37
+    /**
38
+     * @var MediaManagerInterface
39
+     */
40
+    private $authorMediaManager;
41
+
42
+    /**
43
+     * @var EntityManagerInterface
44
+     */
45
+    private $entityManager;
46
+
47
+    /**
48
+     * @var string
49
+     */
50
+    private $cacheDirectory;
51
+
52
+    public function __construct(EntityManagerInterface $entityManager, $cacheDirectory) {
53 53
     $this->entityManager = $entityManager;
54 54
     $this->cacheDirectory = $cacheDirectory;
55
-  }
55
+    }
56 56
 
57
-  /**
58
-   * @param MediaManagerInterface $authorMediaManager
59
-   */
60
-  public function setAuthorMediaManager(MediaManagerInterface $authorMediaManager) {
57
+    /**
58
+     * @param MediaManagerInterface $authorMediaManager
59
+     */
60
+    public function setAuthorMediaManager(MediaManagerInterface $authorMediaManager) {
61 61
     $this->authorMediaManager = $authorMediaManager;
62
-  }
62
+    }
63 63
 
64
-  /**
65
-   * @param GenericEvent $event
66
-   */
67
-  public function processAuthors(GenericEvent $event): void {
64
+    /**
65
+     * @param GenericEvent $event
66
+     */
67
+    public function processAuthors(GenericEvent $event): void {
68 68
     $package = $event->getSubject();
69 69
 
70 70
     if (!$package instanceof PackageInterface) {
71
-      throw new UnexpectedTypeException($package, PackageInterface::class);
71
+        throw new UnexpectedTypeException($package, PackageInterface::class);
72 72
     }
73 73
 
74 74
     $authors = [];
75 75
     /** @var ArticleAuthorInterface $packageAuthor */
76 76
     foreach ($package->getAuthors() as $packageAuthor) {
77
-      $authors[] = $this->handle($packageAuthor);
77
+        $authors[] = $this->handle($packageAuthor);
78 78
     }
79 79
     $package->setAuthors(new ArrayCollection($authors));
80
-  }
81
-
82
-  /**
83
-   * @param ArticleAuthorInterface $object
84
-   *
85
-   * @return ArticleAuthorInterface
86
-   */
87
-  private function handle(ArticleAuthorInterface $object): ArticleAuthorInterface {
80
+    }
81
+
82
+    /**
83
+     * @param ArticleAuthorInterface $object
84
+     *
85
+     * @return ArticleAuthorInterface
86
+     */
87
+    private function handle(ArticleAuthorInterface $object): ArticleAuthorInterface {
88 88
     if (null !== $object->getAvatarUrl()) {
89
-      $filesystem = new Filesystem();
90
-      $pathParts = \pathinfo($object->getAvatarUrl());
91
-      $assetId = \sha1($pathParts['filename']);
92
-      if (null !== $object->getSlug()) {
89
+        $filesystem = new Filesystem();
90
+        $pathParts = \pathinfo($object->getAvatarUrl());
91
+        $assetId = \sha1($pathParts['filename']);
92
+        if (null !== $object->getSlug()) {
93 93
         $assetId = $object->getSlug() . '_' . $assetId;
94
-      }
95
-      $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]);
96
-      if (\count($existingAvatar) > 0) {
94
+        }
95
+        $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]);
96
+        if (\count($existingAvatar) > 0) {
97 97
         $object->setAvatarUrl((string)\reset($existingAvatar));
98 98
 
99 99
         return $object;
100
-      }
100
+        }
101 101
 
102
-      try {
102
+        try {
103 103
         $tempDirectory = $this->cacheDirectory . \DIRECTORY_SEPARATOR . 'downloaded_avatars';
104 104
         $tempLocation = $tempDirectory . \DIRECTORY_SEPARATOR . \sha1($assetId . date('his'));
105 105
         if (!$filesystem->exists($tempDirectory)) {
106
-          $filesystem->mkdir($tempDirectory);
106
+            $filesystem->mkdir($tempDirectory);
107 107
         }
108 108
 
109 109
         $avatarUrl = $object->getAvatarUrl();
110 110
         if (strpos($avatarUrl, "http://") === 0 || strpos($avatarUrl, "https://") === 0) {
111
-          self::downloadFile($avatarUrl, $tempLocation);
111
+            self::downloadFile($avatarUrl, $tempLocation);
112 112
         } else {
113
-          $file = \file_get_contents($avatarUrl);
114
-          if (false === $file) {
113
+            $file = \file_get_contents($avatarUrl);
114
+            if (false === $file) {
115 115
             throw new \Exception('File can\'t be downloaded');
116
-          }
117
-          $filesystem->dumpFile($tempLocation, $file);
116
+            }
117
+            $filesystem->dumpFile($tempLocation, $file);
118 118
         }
119 119
 
120 120
         $uploadedFile = new UploadedFile($tempLocation,
@@ -123,29 +123,29 @@  discard block
 block discarded – undo
123 123
             \filesize($tempLocation),
124 124
             true
125 125
         );
126
-      } catch (\Exception $e) {
126
+        } catch (\Exception $e) {
127 127
         return $object;
128
-      }
129
-      /** @var Image $image */
130
-      $image = $this->authorMediaManager->handleUploadedFile($uploadedFile, $assetId);
131
-      $avatar = $this->createAuthorMedia($object, $image);
132
-      $this->entityManager->persist($avatar);
133
-      $this->entityManager->persist($image);
134
-
135
-      $object->setAvatar($avatar);
136
-      $object->setAvatarUrl((string)$image);
128
+        }
129
+        /** @var Image $image */
130
+        $image = $this->authorMediaManager->handleUploadedFile($uploadedFile, $assetId);
131
+        $avatar = $this->createAuthorMedia($object, $image);
132
+        $this->entityManager->persist($avatar);
133
+        $this->entityManager->persist($image);
134
+
135
+        $object->setAvatar($avatar);
136
+        $object->setAvatarUrl((string)$image);
137 137
     }
138 138
 
139 139
     return $object;
140
-  }
140
+    }
141 141
 
142
-  private function createAuthorMedia(ArticleAuthorInterface $articleAuthor, Image $image): AuthorMediaInterface {
142
+    private function createAuthorMedia(ArticleAuthorInterface $articleAuthor, Image $image): AuthorMediaInterface {
143 143
     return new AuthorMedia('avatar', $articleAuthor, $image);
144
-  }
144
+    }
145 145
 
146
-  private static function downloadFile($url, $location) {
146
+    private static function downloadFile($url, $location) {
147 147
     $handlerStack = HandlerStack::create(new CurlHandler());
148 148
     $client = new Client(['handler' => $handlerStack]);
149 149
     $client->request('GET', $url, ['sink' => $location]);
150
-  }
150
+    }
151 151
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
       $pathParts = \pathinfo($object->getAvatarUrl());
91 91
       $assetId = \sha1($pathParts['filename']);
92 92
       if (null !== $object->getSlug()) {
93
-        $assetId = $object->getSlug() . '_' . $assetId;
93
+        $assetId = $object->getSlug().'_'.$assetId;
94 94
       }
95 95
       $existingAvatar = $this->entityManager->getRepository(Image::class)->findBy(['assetId' => $assetId]);
96 96
       if (\count($existingAvatar) > 0) {
97
-        $object->setAvatarUrl((string)\reset($existingAvatar));
97
+        $object->setAvatarUrl((string) \reset($existingAvatar));
98 98
 
99 99
         return $object;
100 100
       }
101 101
 
102 102
       try {
103
-        $tempDirectory = $this->cacheDirectory . \DIRECTORY_SEPARATOR . 'downloaded_avatars';
104
-        $tempLocation = $tempDirectory . \DIRECTORY_SEPARATOR . \sha1($assetId . date('his'));
103
+        $tempDirectory = $this->cacheDirectory.\DIRECTORY_SEPARATOR.'downloaded_avatars';
104
+        $tempLocation = $tempDirectory.\DIRECTORY_SEPARATOR.\sha1($assetId.date('his'));
105 105
         if (!$filesystem->exists($tempDirectory)) {
106 106
           $filesystem->mkdir($tempDirectory);
107 107
         }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
       $this->entityManager->persist($image);
134 134
 
135 135
       $object->setAvatar($avatar);
136
-      $object->setAvatarUrl((string)$image);
136
+      $object->setAvatarUrl((string) $image);
137 137
     }
138 138
 
139 139
     return $object;
Please login to merge, or discard this patch.