Issues (17)

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/Config.php (5 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
namespace TheCodingMachine\WashingMachine\Commands;
5
6
7
use Cz\Git\GitRepository;
8
use Symfony\Component\Console\Input\InputInterface;
9
10
/**
11
 * Object to retrieve the command configuration based on environment variables and input.
12
 */
13
class Config
14
{
15
    /**
16
     * @var InputInterface
17
     */
18
    private $input;
19
20
    public function __construct(InputInterface $input)
21
    {
22
        $this->input = $input;
23
    }
24
25
    public function getCloverFilePath() : string
26
    {
27
        return $this->input->getOption('clover');
28
    }
29
30
    public function getCrap4JFilePath() : string
31
    {
32
        return $this->input->getOption('crap4j');
33
    }
34
35 View Code Duplication
    public function getGitlabApiToken() : string
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $gitlabApiToken = $this->input->getOption('gitlab-api-token');
38
        if ($gitlabApiToken === null) {
39
            $gitlabApiToken = getenv('GITLAB_API_TOKEN');
40
            if ($gitlabApiToken === false) {
41
                throw new \RuntimeException('Could not find the Gitlab API token in the "GITLAB_API_TOKEN" environment variable. Either set this environment variable or pass the token via the --gitlab-api-token command line option.');
42
            }
43
        }
44
        return $gitlabApiToken;
45
    }
46
47
    public function getGitlabUrl() : string
48
    {
49
        $gitlabUrl = $this->input->getOption('gitlab-url');
50
        if ($gitlabUrl === null) {
51
            $ciProjectUrl = getenv('CI_REPOSITORY_URL');
52
            if ($ciProjectUrl === false) {
53
                $ciProjectUrl = getenv('CI_BUILD_REPO');
54
                if ($ciProjectUrl === false) {
55
                    throw new \RuntimeException('Could not find the Gitlab URL in the "CI_REPOSITORY_URL" (Gitlab 9+) or "CI_BUILD_REPO" (Gitlab 8.x) environment variable (usually set by Gitlab CI). Either set this environment variable or pass the URL via the --gitlab-url command line option.');
56
                }
57
            }
58
            $parsed_url = parse_url($ciProjectUrl);
59
            $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
60
            $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
61
            $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
62
            $gitlabUrl = $scheme.$host.$port;
63
        }
64
        return rtrim($gitlabUrl, '/');
65
    }
66
67
    public function getGitlabApiUrl() : string
68
    {
69
        return $this->getGitlabUrl().'/api/v3/';
70
    }
71
72 View Code Duplication
    public function getGitlabProjectName() : string
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $projectName = $this->input->getOption('gitlab-project-name');
75
        if ($projectName === null) {
76
            $projectDir = getenv('CI_PROJECT_DIR');
77
            if ($projectDir === false) {
78
                throw new \RuntimeException('Could not find the Gitlab project name in the "CI_PROJECT_DIR" environment variable (usually set by Gitlab CI). Either set this environment variable or pass the project name via the --gitlab-project-name command line option.');
79
            }
80
            $projectName = substr($projectDir, 8);
81
        }
82
        return $projectName;
83
    }
84
85 View Code Duplication
    public function getCommitSha() : string
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        $commitSha = $this->input->getOption('commit-sha');
88
89
        if ($commitSha === null) {
90
            $commitSha = getenv('CI_COMMIT_SHA');
91
            if ($commitSha === false) {
92
                $commitSha = getenv('CI_BUILD_REF');
93
                if ($commitSha === false) {
94
                    throw new \RuntimeException('Could not find the Gitlab build reference in the "CI_COMMIT_SHA" (Gitlab 9+) or "CI_BUILD_REF" (Gitlab 8.x) environment variable (usually set by Gitlab CI). Either set this environment variable or pass the build reference via the --commit-sha command line option.');
95
                }
96
            }
97
        }
98
99
        return $commitSha;
100
    }
101
102 View Code Duplication
    public function getJobStage() : string
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $commitSha = $this->input->getOption('job-stage');
105
106
        if ($commitSha === null) {
107
            $commitSha = getenv('CI_JOB_STAGE');
108
            if ($commitSha === false) {
109
                throw new \RuntimeException('Could not find the Gitlab job stage in the "CI_JOB_STAGE" (Gitlab 9+) environment variable (usually set by Gitlab CI). Either set this environment variable or pass the job stage via the --job_stage command line option.');
110
            }
111
        }
112
113
        return $commitSha;
114
    }
115
116 View Code Duplication
    public function getGitlabBuildId() : int
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $buildId = $this->input->getOption('gitlab-job-id');
119
        if ($buildId === null) {
120
            $buildId = getenv('CI_BUILD_ID');
121
            if ($buildId === false) {
122
                $buildId = getenv('CI_JOB_ID');
123
                if ($buildId === false) {
124
                    throw new \RuntimeException('Could not find the Gitlab build id in the "CI_JOB_ID" (Gitlab 9+) or "CI_BUILD_ID" (Gitlab 8.x) environment variable (usually set by Gitlab CI). Either set this environment variable or pass the build id via the --gitlab-job-id command line option.');
125
                }
126
            }
127
        }
128
        return $buildId;
129
    }
130
131
    /**
132
     * Returns the current branch name (from Git)
133
     * @return string
134
     */
135
    public function getCurrentBranchName() : string
136
    {
137
        // Gitlab 8.x
138
        $branchName = getenv('CI_BUILD_REF_NAME');
139
        if ($branchName !== false) {
140
            return $branchName;
141
        }
142
143
        // Gitlab 9+
144
        $branchName = getenv('CI_COMMIT_REF_NAME');
145
        if ($branchName !== false) {
146
            return $branchName;
147
        }
148
149
        $repo = new GitRepository(getcwd());
150
        return $repo->getCurrentBranchName();
151
    }
152
153
    public function getFiles() : array
154
    {
155
        return $this->input->getOption('file');
156
    }
157
158
    public function isOpenIssue() : bool
159
    {
160
        return $this->input->getOption('open-issue');
161
    }
162
}
163