Issues (94)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Command/CacheCommandTrait.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Command;
13
14
use Imagine\Exception\RuntimeException;
15
use Liip\ImagineBundle\Component\Console\Style\ImagineStyle;
16
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
17
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * @internal
23
 */
24
trait CacheCommandTrait
25
{
26
    /**
27
     * @var CacheManager
28
     */
29
    private $cacheManager;
30
31
    /**
32
     * @var FilterManager
33
     */
34
    private $filterManager;
35
36
    /**
37
     * @var ImagineStyle
38
     */
39
    private $io;
40
41
    /**
42
     * @var bool
43
     */
44
    private $outputMachineReadable;
45
46
    /**
47
     * @var int
48
     */
49
    private $failures = 0;
50
51
    private function setupOutputStyle(InputInterface $input, OutputInterface $output): void
52
    {
53
        $this->outputMachineReadable = $input->getOption('as-script');
0 ignored issues
show
Documentation Bug introduced by
It seems like $input->getOption('as-script') can also be of type string or array<integer,string>. However, the property $outputMachineReadable is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
54
        $this->io = new ImagineStyle($input, $output, $this->outputMachineReadable ? false : !$input->getOption('no-colors'));
55
    }
56
57
    /**
58
     * @return array[]
59
     */
60
    private function resolveInputFiltersAndPaths(InputInterface $input): array
61
    {
62
        return [
63
            $input->getArgument('paths'),
64
            $this->normalizeFilterList($input->getOption('filter')),
65
        ];
66
    }
67
68
    /**
69
     * @param string[] $filters
70
     *
71
     * @return string[]
72
     */
73
    private function normalizeFilterList(array $filters): array
74
    {
75
        if (0 < \count($filters)) {
76
            return $filters;
77
        }
78
79
        if (0 < \count($filters = array_keys((array) $this->filterManager->getFilterConfiguration()->all()))) {
80
            return $filters;
81
        }
82
83
        throw new RuntimeException('No filters have been defined in the active configuration!');
84
    }
85
86
    private function outputCommandHeader(): void
87
    {
88
        if (!$this->outputMachineReadable) {
89
            $this->io->title($this->getName(), 'liip/imagine-bundle');
0 ignored issues
show
It seems like getName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
90
        }
91
    }
92
93
    /**
94
     * @param string[] $images
95
     * @param string[] $filters
96
     */
97
    private function outputCommandResult(array $images, array $filters, string $singularAction): void
98
    {
99
        if (!$this->outputMachineReadable) {
100
            $wordPluralizer = function (int $count, string $singular) {
101
                return 1 === $count ? $singular : sprintf('%ss', $singular);
102
            };
103
104
            $imagePathsSize = \count($images);
105
            $filterSetsSize = \count($filters);
106
            $allActionsSize = 0 === $imagePathsSize ? $filterSetsSize : ($filterSetsSize * $imagePathsSize) - $this->failures;
107
            $allActionsWord = $wordPluralizer($allActionsSize, $singularAction);
108
109
            $rootTextOutput = sprintf('Completed %d %s', $allActionsSize, $allActionsWord);
110
111
            $detailTextFormat = '%d %s';
112
113
            $detailTextsOutput = [];
114
115
            if (0 !== $imagePathsSize) {
116
                $detailTextsOutput[] = sprintf($detailTextFormat, $imagePathsSize, $wordPluralizer($imagePathsSize, 'image'));
117
            }
118
119
            if (0 !== $filterSetsSize) {
120
                $detailTextsOutput[] = sprintf($detailTextFormat, $filterSetsSize, $wordPluralizer($filterSetsSize, 'filter'));
121
            }
122
123
            if (!empty($detailTextsOutput)) {
124
                $rootTextOutput = sprintf('%s (%s)', $rootTextOutput, implode(', ', $detailTextsOutput));
125
            }
126
127
            if ($this->failures) {
128
                $this->io->critBlock(sprintf('%s %%s', $rootTextOutput), [
129
                    sprintf('[encountered %d failures]', $this->failures),
130
                ]);
131
            } else {
132
                $this->io->okayBlock($rootTextOutput);
133
            }
134
        }
135
    }
136
137
    private function getResultCode(): int
138
    {
139
        return 0 === $this->failures ? 0 : 255;
140
    }
141
}
142