Issues (2)

Security Analysis    no request data  

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/ConsoleTableWriter.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 plumphp/plum-console.
5
 *
6
 * (c) Florian Eckerstorfer <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Plum\PlumConsole;
13
14
use Cocur\Vale\Vale;
15
use InvalidArgumentException;
16
use Plum\Plum\Writer\WriterInterface;
17
use Symfony\Component\Console\Helper\Table;
18
19
/**
20
 * ConsoleTableWriter.
21
 *
22
 * @author    Florian Eckerstorfer
23
 * @copyright 2015 Florian Eckerstorfer
24
 */
25
class ConsoleTableWriter implements WriterInterface
26
{
27
    /**
28
     * @var Table
29
     */
30
    protected $table;
31
32
    /**
33
     * @var string[]|null
34
     */
35
    protected $header;
36
37
    /**
38
     * @var bool
39
     */
40
    protected $autoDetectHeader = false;
41
42
    /**
43
     * @param Table $table
44
     *
45
     * @codeCoverageIgnore
46
     */
47
    public function __construct(Table $table)
48
    {
49
        $this->table = $table;
50
    }
51
52
    /**
53
     * @param string[] $header
54
     *
55
     * @return ConsoleTableWriter
56
     */
57 1
    public function setHeader(array $header)
58
    {
59 1
        $this->header = $header;
60
61 1
        return $this;
62
    }
63
64
    /**
65
     * @param bool $autoDetectHeader
66
     *
67
     * @return ConsoleTableWriter
68
     */
69 1
    public function autoDetectHeader($autoDetectHeader = true)
70
    {
71 1
        $this->autoDetectHeader = $autoDetectHeader;
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * Write the given item.
78
     *
79
     * @param mixed $item
80
     */
81 5
    public function writeItem($item)
82
    {
83 5
        if ($this->autoDetectHeader && !$this->header) {
84 2
            $this->handleAutoDetectHeader($item);
85 1
        }
86
87 4
        $this->table->addRow(
88 4
            $this->getValues($item, $this->getKeys($item))
89 3
        );
90 3
    }
91
92
    /**
93
     * Prepare the writer.
94
     *
95
     *
96
     * @codeCoverageIgnore
97
     */
98
    public function prepare()
99
    {
100
        if ($this->header !== null) {
101
            $this->table->setHeaders($this->header);
102
        }
103
    }
104
105
    /**
106
     * Finish the writer.
107
     */
108 1
    public function finish()
109
    {
110 1
        $this->table->render();
111 1
    }
112
113
    /**
114
     * @param mixed $item
115
     */
116 2
    protected function handleAutoDetectHeader($item)
117
    {
118 2
        if (!is_array($item)) {
119 1
            throw new InvalidArgumentException('Plum\PlumConsole\ConsoleTableWriter can only auto detect headers for '.
120 1
                                               'array items. For items of a type other than array the headers have '.
121 1
                                               'to be set manually.');
122
        }
123
124 1
        $this->header = array_keys($item);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_keys($item) of type array<integer,integer|string> is incompatible with the declared type array<integer,string>|null of property $header.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
125 1
        $this->table->setHeaders($this->header);
126 1
    }
127
128
    /**
129
     * @param mixed $item
130
     *
131
     * @return string[]
0 ignored issues
show
Should the return type not be array<integer|string>?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
132
     */
133 4
    protected function getKeys($item)
134
    {
135 4
        if (is_array($item)) {
136 2
            return array_keys($item);
137 2
        } elseif ($this->header && is_object($item)) {
138 1
            return $this->header;
139
        }
140
141 1
        throw new InvalidArgumentException(sprintf(
142
            'Plum\PlumConsole\ConsoleTableWriter currently only supports array items or objects if headers '.
143 1
            'are set using the setHeader() method. You have passed an item of type "%s" to writeItem().',
144 1
            gettype($item)
145 1
        ));
146
    }
147
148
    /**
149
     * @param mixed    $item
150
     * @param string[] $keys
151
     *
152
     * @return array
153
     */
154 3
    protected function getValues($item, array $keys)
155
    {
156 3
        $values = [];
157 3
        foreach ($keys as $key) {
158 3
            $values[] = Vale::get($item, $key);
159 3
        }
160
161 3
        return $values;
162
    }
163
}
164