Issues (74)

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/helpers/InitCommandHelperTrait.php (3 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
namespace keeko\tools\helpers;
3
4
use keeko\tools\services\CommandService;
5
use keeko\tools\utils\NamespaceResolver;
6
use Symfony\Component\Process\ExecutableFinder;
7
use Symfony\Component\Process\Process;
8
use Symfony\Component\Process\ProcessUtils;
9
10
trait InitCommandHelperTrait {
11
	
12
	private $gitConfig;
13
	
14
	/**
15
	 * @return CommandService
16
	 */
17
	abstract protected function getService();
18
	
19
	private function getPackage() {
20
		return $this->getService()->getPackageService()->getPackage();
21
	}
22
23
	private function getPackageKeeko($type) {
24
		$keeko = $this->getPackage()->getKeeko();
25
		$pkg = $keeko->getKeekoPackage($type);
26
	
27
		if ($pkg == null) {
28
			throw new \Exception(sprintf('Unknown package type <%s>', $type));
29
		}
30
	
31
		return $pkg;
32
	}
33
	
34
	private function getPackageTitle() {
35
		$input = $this->getService()->getIOService()->getInput();
36
		$type = $this->getPackageType();
37
		$keeko = $this->getPackageKeeko($type);
38
		$pkgTitle = $keeko === null ? null : $keeko->getTitle();
39
		$title = $input->getOption('title');
40
		$title = $title === null && !empty($pkgTitle) ? $pkgTitle : $title;
41
	
42
		// fallback to default value
43
		if ($title === null) {
44
			$title = ucwords(str_replace('/', ' ', $input->getOption('name')));
45
		}
46
	
47
		return $title;
48
	}
49
	
50
	private function getPackageClass() {
51
		$input = $this->getService()->getIOService()->getInput();
52
		$type = $this->getPackageType();
53
		$keeko = $this->getPackageKeeko($type);
54
		$pkgClass = $keeko === null ? null : $keeko->getClass();
55
		$classname = $input->getOption('classname');
56
		$classname = $classname === null && !empty($pkgClass) ? $pkgClass : $classname;
57
	
58
		// default value
59
		if ($classname === null) {
60
			$pkgName = $this->getPackage()->getFullName();
61
			$parts = explode('/', $pkgName);
62
			$ns = $input->getOption('namespace');
63
			$namespace = !empty($ns) ? $ns : str_replace('/', '\\', $pkgName);
64
			$classname = $namespace . '\\' . ucfirst($parts[1]);
65
	
66
			// suffix
67
			if ($type === 'module') {
68
				$classname .= 'Module';
69
			} else if ($type === 'app') {
70
				$classname .= 'Application';
71
			}
72
		}
73
	
74
		return $classname;
75
	}
76
	
77
	private function getPackageType() {
78
		$input = $this->getService()->getIOService()->getInput();
79
		$type = $input->getOption('type');
80
		$pkgType = $this->getPackage()->getType();
81
		return $type === null && !empty($pkgType)
82
		? str_replace('keeko-', '', $pkgType)
83
		: $type;
84
	}
85
	
86
	private function getPackageName() {
87
		$input = $this->getService()->getIOService()->getInput();
88
		$name = $input->getOption('name');
89
		$pkgName = $this->getPackage()->getFullName();
90
		return $name === null && !empty($pkgName) ? $pkgName : $name;
91
	}
92
	
93
	private function getPackageDescription() {
94
		$input = $this->getService()->getIOService()->getInput();
95
		$desc = $input->getOption('description');
96
		$pkgDesc = $this->getPackage()->getDescription();
97
		return $desc === null && !empty($pkgDesc) ? $pkgDesc : $desc;
98
	}
99
	
100
	private function getPackageLicense() {
101
		$input = $this->getService()->getIOService()->getInput();
102
		$license = $input->getOption('license');
103
		$pkgLicense = $this->getPackage()->getLicense();
104
		return $license === null && !empty($pkgLicense) ? $pkgLicense : $license;
105
	}
106
	
107
	private function hasAutoload() {
108
		return NamespaceResolver::getNamespace('src', $this->package);
0 ignored issues
show
The property package does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
109
	}
110
	
111
	private function validateName($name) {
112
		if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $name)) {
113
			throw new \InvalidArgumentException(
114
				'The package name ' . $name . ' 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_.-]+'
115
			);
116
		}
117
	}
118
	
119
	private function setAutoload($namespace) {
120
		$autoload = $this->getPackage()->getAutoload();
121
	
122
		// remove existing src/ entry
123
		$autoload->getPsr0()->removePath('src');
124
		$autoload->getPsr4()->removePath('src');
125
	
126
		// add src/ to psr4
127
		$autoload->getPsr4()->setPath($namespace, 'src/');
128
	}
129
	
130
	protected function getGitConfig() {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
131
		if (null !== $this->gitConfig) {
132
			return $this->gitConfig;
133
		}
134
		$finder = new ExecutableFinder();
135
		$gitBin = $finder->find('git');
136
		$cmd = new Process(sprintf('%s config -l', ProcessUtils::escapeArgument($gitBin)));
137
		$cmd->run();
138
		if ($cmd->isSuccessful()) {
139
			$this->gitConfig = [];
140
			$matches = [];
141
			preg_match_all('{^([^=]+)=(.*)$}m', $cmd->getOutput(), $matches, PREG_SET_ORDER);
142
			foreach ($matches as $match) {
0 ignored issues
show
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
143
				$this->gitConfig[$match[1]] = $match[2];
144
			}
145
			return $this->gitConfig;
146
		}
147
		return $this->gitConfig = [];
148
	}
149
}