ConsoleController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Rvdlee\ZfImageOptimiser\Controller;
4
5
use Exception;
6
use Rvdlee\ZfImageOptimiser\Service\ImageOptimiserService;
7
use Zend\Mvc\Controller\AbstractActionController;
0 ignored issues
show
Bug introduced by
The type Zend\Mvc\Controller\AbstractActionController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class ConsoleController extends AbstractActionController
10
{
11
    /**
12
     * @var ImageOptimiserService
13
     */
14
    protected $imageOptimiserService;
15
16
    public function __construct(ImageOptimiserService $imageOptimiserService)
17
    {
18
        $this->setImageOptimiserService($imageOptimiserService);
19
    }
20
21
    /**
22
     * Console wrapper for service
23
     *
24
     * @throws Exception
25
     */
26
    public function optimiseImagesAction()
27
    {
28
        /** @var string $fromYear */
29
        $image = $this->params()->fromRoute('image');
30
        if ($image === null) {
31
            die('You need the --image param.');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
32
        }
33
34
        try {
35
            $this->getImageOptimiserService()->optimize($image);
36
        } catch (Exception $exception) {
37
            throw $exception;
38
        }
39
    }
40
41
    /**
42
     * @return ImageOptimiserService
43
     */
44
    public function getImageOptimiserService() : ImageOptimiserService
45
    {
46
        return $this->imageOptimiserService;
47
    }
48
49
    /**
50
     * @param ImageOptimiserService $imageOptimiserService
51
     *
52
     * @return ConsoleController
53
     */
54
    public function setImageOptimiserService(ImageOptimiserService $imageOptimiserService) : ConsoleController
55
    {
56
        $this->imageOptimiserService = $imageOptimiserService;
57
58
        return $this;
59
    }
60
}