Issues (45)

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.

src/TreeHouse/WorkerBundle/Command/ListCommand.php (6 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
namespace TreeHouse\WorkerBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use TreeHouse\WorkerBundle\QueueManager;
12
13
class ListCommand extends Command
14
{
15
    /**
16
     * @var QueueManager
17
     */
18
    protected $manager;
19
20
    /**
21
     * @var int
22
     */
23
    protected $lineCount;
24
25
    /**
26
     * @param QueueManager $queueManager
27
     */
28
    public function __construct(QueueManager $queueManager)
29
    {
30
        $this->manager = $queueManager;
31
32
        parent::__construct();
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    protected function configure()
39
    {
40
        $this
41
            ->setName('worker:list')
42
            ->addArgument('action', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Selects which actions to clear. Defaults to all actions')
43
            ->addOption('refresh', null, InputOption::VALUE_OPTIONAL, 'Refresh rate in seconds, only applies for interactive commands', 1)
44
            ->addOption('empty', null, InputOption::VALUE_NONE, 'Show empty actions')
45
            ->setDescription('List actions and their stats')
46
        ;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    protected function execute(InputInterface $input, OutputInterface $output)
53
    {
54
        $actions = $input->getArgument('action');
55
        if (empty($actions)) {
56
            $actions = array_keys($this->manager->getExecutors());
57
        }
58
59
        $empty   = $input->getOption('empty');
60
        $refresh = $input->getOption('refresh');
61
62
        if ($input->isInteractive()) {
63
            $output->writeln([
0 ignored issues
show
array('', sprintf('This ...o exit', $refresh), '') is of type array<integer,string,{"0..."string","2":"string"}>, but the function expects a string|object<Symfony\Co...onsole\Output\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
                '',
65
                sprintf('This list refreshes every <comment>%d</comment> second(s), type CTRL-C to exit', $refresh),
66
                '',
67
            ]);
68
69
            while (true) {
70
                $this->render($output, $actions, $empty);
0 ignored issues
show
It seems like $actions defined by $input->getArgument('action') on line 54 can also be of type string; however, TreeHouse\WorkerBundle\C...d\ListCommand::render() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
71
                sleep($refresh);
72
            }
73
        } else {
74
            $this->render($output, $actions, $input->getOption('empty'));
0 ignored issues
show
It seems like $actions defined by $input->getArgument('action') on line 54 can also be of type string; however, TreeHouse\WorkerBundle\C...d\ListCommand::render() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
75
        }
76
77
        return 0;
78
    }
79
80
    /**
81
     * @param OutputInterface $output
82
     * @param array           $actions
83
     * @param bool            $empty
84
     */
85
    protected function render(OutputInterface $output, array $actions, $empty = false)
86
    {
87
        $fields = [
88
            'action'   => 'name',
89
            'workers'  => 'current-watching',
90
            'reserved' => 'current-jobs-reserved',
91
            'ready'    => 'current-jobs-ready',
92
            'urgent'   => 'current-jobs-urgent',
93
            'delayed'  => 'current-jobs-delayed',
94
            'buried'   => 'current-jobs-buried',
95
        ];
96
97
        $table = new Table($output);
98
        $table->setHeaders(array_keys($fields));
99
100
        $rows = [];
101
        foreach ($actions as $action) {
102
            if (!$stats = $this->manager->getActionStats($action)) {
0 ignored issues
show
Are you sure the assignment to $stats is correct as $this->manager->getActionStats($action) (which targets TreeHouse\WorkerBundle\Q...nager::getActionStats()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
103
                if (!$empty) {
104
                    continue;
105
                }
106
107
                $stats = array_combine(array_values($fields), array_fill(0, sizeof($fields), '-'));
108
                $stats['name'] = $action;
109
            }
110
111
            $rows[$action] = array_map(
112
                function ($field) use ($stats) {
113
                    return $stats[$field];
114
                },
115
                $fields
116
            );
117
        }
118
119
        ksort($rows);
120
121
        $table->addRows($rows);
122
123
        if ($this->lineCount) {
124
            // move back to the beginning
125
            $output->write("\033[0G");
126
            $output->write(sprintf("\033[%dA", $this->lineCount));
127
128
            // overwrite the complete table before rendering the new one
129
            $width = $this->getApplication()->getTerminalDimensions()[0];
0 ignored issues
show
The method getTerminalDimensions() does not seem to exist on object<Symfony\Component\Console\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130
            $lines = array_fill(0, $this->lineCount, str_pad('', $width, ' '));
131
            $output->writeln($lines);
0 ignored issues
show
$lines is of type array, but the function expects a string|object<Symfony\Co...onsole\Output\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
132
133
            $output->write(sprintf("\033[%dA", $this->lineCount));
134
        }
135
136
        // render the new table
137
        $table->render();
138
139
        // top table border + header + header border + bottom table border = 4
140
        $this->lineCount = 4 + sizeof($rows);
141
    }
142
}
143