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.

IndexController::setImageProcessing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Smart image resizing (and manipulation) by url module for Zend Framework 3
4
 *
5
 * @link      http://github.com/tck/zf2-imageresizer for the canonical source repository
6
 * @copyright Copyright (c) 2017 Tobias Knab
7
 * 
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace TckImageResizer\Controller;
13
14
use Zend\Mvc\Controller\AbstractActionController;
15
use TckImageResizer\Service\ImageProcessing;
16
17
/**
18
 * Index controller
19
 * 
20
 * @package TckImageResizer
21
 */
22
class IndexController extends AbstractActionController
23
{
24
    /**
25
     * @var ImageProcessing
26
     */
27
    protected $imageProcessing;
28
    
29
    /**
30
     * @var string
31
     */
32
    protected $publicDirectory;
33
    
34
    /**
35
     * constructor
36
     *
37
     * @param ImageProcessing $imageProcessing
38
     * @param string $publicDirectory
39
     */
40
    public function __construct(ImageProcessing $imageProcessing, $publicDirectory = 'public')
41 15
    {
42
        $this->setImageProcessing($imageProcessing);
43 15
        $this->publicDirectory = $publicDirectory;
44 15
    }
45 15
    
46
    /**
47
     * set the image processing service
48
     *
49
     * @param ImageProcessing $imageProcessing
50
     * @return $this
51
     */
52
    public function setImageProcessing(ImageProcessing $imageProcessing)
53 15
    {
54
        $this->imageProcessing = $imageProcessing;
55 15
56
        return $this;
57 15
    }
58
    
59
    /**
60
     * Get the image processing service
61
     * 
62
     * @return ImageProcessing
63
     */
64
    public function getImageProcessing()
65 12
    {
66
        return $this->imageProcessing;
67 12
    }
68
69
    /**
70
     * @return \Zend\Http\Response
71
     */
72
    public function resizeAction()
73 12
    {
74
        $source = $this->publicDirectory . '/'
75 12
                . $this->params('file')
76 12
                . '.' . $this->params('extension');
77 12
        
78
        $targetExtension = $this->params('extension');
79 12
        if (!file_exists($source)) {
80 12
            $source = null;
81 3
            $targetExtension = '404.' . $targetExtension . '.png';
82 3
        }
83 3
        
84
        $target = $this->publicDirectory . '/processed/'
85 12
                . $this->params('file')
86 12
                . '.$' . $this->params('command')
87 12
                . '.' . $targetExtension;
88 12
        
89
        if ($source) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $source of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
90 12
            $this->getImageProcessing()->process($source, $target, $this->params('command'));
91 9
            
92
        } else {
93 9
            $this->getImageProcessing()->process404($target, $this->params('command'));
94 3
        }
95
        
96
        $imageInfo = getimagesize($target);
97 12
        $mimeType = $imageInfo['mime'];
98 12
99
        /** @var \Zend\Http\Response $response */
100
        $response = $this->getResponse();
101 12
        $response->setContent(file_get_contents($target));
102 12
        $response->setStatusCode($source ? 200 : 404);
103 12
        $response
104
            ->getHeaders()
105 12
            ->addHeaderLine('Content-Transfer-Encoding', 'binary')
106 12
            ->addHeaderLine('Content-Type', $mimeType);
107 12
        
108
        return $response;
109 12
    }
110
}
111