GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( d79ade...faea90 )
by Odiseo
02:53
created

ArticleImageUploadListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A uploadImages() 0 12 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\BlogBundle\EventListener;
6
7
use Odiseo\BlogBundle\Model\ArticleInterface;
8
use Odiseo\BlogBundle\Model\ImageInterface;
9
use Odiseo\BlogBundle\Uploader\ImageUploaderInterface;
10
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
11
use Webmozart\Assert\Assert;
12
13
final class ArticleImageUploadListener
14
{
15
    /** @var ImageUploaderInterface */
16
    private $uploader;
17
18
    public function __construct(ImageUploaderInterface $uploader)
19
    {
20
        $this->uploader = $uploader;
21
    }
22
23
    public function uploadImages(ResourceControllerEvent $event): void
24
    {
25
        $article = $event->getSubject();
26
27
        Assert::isInstanceOf($article, ArticleInterface::class);
28
29
        $images = $article->getImages();
30
31
        /** @var ImageInterface $image */
32
        foreach ($images as $image) {
33
            if (null !== $image && true === $image->hasFile()) {
34
                $this->uploader->upload($image);
35
            }
36
        }
37
    }
38
}
39