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/Commands/CreateCommand.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
namespace Ptondereau\PackMe\Commands;
4
5
use Ptondereau\PackMe\Crafters\CrafterInterface;
6
use Ptondereau\PackMe\Package;
7
use Symfony\Component\Console\Helper\HelperSet;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class CreateCommand.
13
 */
14
class CreateCommand extends AbstractBaseCommand
15
{
16
    /**
17
     * Crafter.
18
     *
19
     * @var CrafterInterface
20
     */
21
    protected $crafter;
22
23
    /**
24
     * CreateCommand constructor.
25
     *
26
     * @param CrafterInterface $crafter
27
     * @param HelperSet        $helperSet
28
     */
29 9
    public function __construct(CrafterInterface $crafter, HelperSet $helperSet)
30
    {
31 9
        parent::__construct($helperSet);
32 9
        $this->crafter = $crafter;
33 9
    }
34
35
    public function __invoke($dir, InputInterface $input, OutputInterface $output)
36
    {
37
        $this->input = $input;
38
        $this->output = $output;
0 ignored issues
show
The property output cannot be accessed from this context as it is declared private in class Ptondereau\PackMe\Commands\AbstractBaseCommand.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
39
40
        $output->writeln('<info>I need to know a little more about your future awesome laravel package...</info>');
41
        $output->writeln('');
42
43
        $package = new Package(
44
            $this->askForPackageName(),
45
            $this->askForAuthor(),
46
            $dir
47
        );
48
        $package->setDescription($this->askForDescription());
49
50
        $output->writeln('');
51
        $output->writeln('<info>Crafting your laravel package...</info>');
52
53
        $this->crafter->craft($package);
54
55
        $output->writeln('');
56
        $output->writeln('<info>Successfully crafted!</info>');
57
    }
58
59
    /**
60
     * @param string $package
61
     *
62
     * @return string
63
     */
64
    protected function askForPackageName($package = 'vendor/package')
65
    {
66
        return $this->askAndValidate(
67
            'Package name (<vendor>/<name>) [<comment>'.$package.'</comment>]: ',
68
            function ($value) use ($package) {
69
                if (null === $value) {
70
                    return $package;
71
                }
72
                if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $value)) {
73
                    throw new \InvalidArgumentException(
74
                        'The package name '.$value.' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+'
75
                    );
76
                }
77
78
                return $value;
79
            },
80
            null,
81
            $package
82
        );
83
    }
84
85
    /**
86
     * @param string $author
87
     *
88
     * @return string
89
     */
90
    protected function askForAuthor($author = 'Author Name <[email protected]>')
91
    {
92
        $self = $this;
93
94
        return $this->askAndValidate(
95
            'Author [<comment>'.$author.'</comment>]: ',
96
            function ($value) use ($self, $author) {
97
                if (null === $value) {
98
                    return $author;
99
                }
100
101
                $value = $value ?: $author;
102
                $parsed = $self->parseAuthorString($value);
103
104
                return sprintf('%s <%s>', $parsed['name'], $parsed['email']);
105
            },
106
            null,
107
            $author
108
        );
109
    }
110
111
    /**
112
     * @param bool|string $description
113
     *
114
     * @return string
115
     */
116
    protected function askForDescription($description = false)
117
    {
118
        $description = $description ?: false;
119
120
        return $this->ask(
121
            'Description [<comment>'.$description.'</comment>]: ',
122
            $description
0 ignored issues
show
It seems like $description defined by $description ?: false on line 118 can also be of type boolean; however, Ptondereau\PackMe\Comman...tractBaseCommand::ask() does only seem to accept null|string, 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...
123
        );
124
    }
125
126
    /**
127
     * Parse the author string.
128
     *
129
     * @private
130
     *
131
     * @param string $author
132
     *
133
     * @return array
134
     */
135 9
    private function parseAuthorString($author)
136
    {
137
        if (
138 9
            preg_match('/^(?P<name>[- \.,\p{L}\p{N}\'’]+) <(?P<email>.+?)>$/u', $author, $match)
139 9
            && $this->isValidEmail($match['email'])
140 3
        ) {
141
            return [
142 3
                'name'  => trim($match['name']),
143 3
                'email' => $match['email'],
144 1
            ];
145
        }
146
147 6
        throw new \InvalidArgumentException(
148
            'Invalid author string.  Must be in the format: '.
149 4
            'John Smith <[email protected]>'
150 2
        );
151
    }
152
153
    /**
154
     * Check if a given email is a good email.
155
     *
156
     * @param $email
157
     *
158
     * @return bool
159
     */
160 6
    private function isValidEmail($email)
161
    {
162
        // assume it's valid if we can't validate it
163 6
        if (!function_exists('filter_var')) {
164
            return true;
165
        }
166
        // php <5.3.3 has a very broken email validator, so bypass checks
167 6
        if (PHP_VERSION_ID < 50303) {
168
            return true;
169
        }
170
171 6
        return false !== filter_var($email, FILTER_VALIDATE_EMAIL);
172
    }
173
}
174