This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 SilverStripe\Porter\Commands; |
||
4 | |||
5 | use SilverStripe\Porter\Helpers\ValidationHelper; |
||
6 | use Symfony\Component\Filesystem\Filesystem; |
||
7 | use Symfony\Component\Console\Command\Command; |
||
8 | use Symfony\Component\Console\Input\InputOption; |
||
9 | use Symfony\Component\Console\Input\InputArgument; |
||
10 | use Symfony\Component\Console\Input\InputInterface; |
||
11 | use Symfony\Component\Console\Output\OutputInterface; |
||
12 | use Symfony\Component\Yaml\Exception\RuntimeException; |
||
13 | |||
14 | /** |
||
15 | * Class CreateDataObjectCommand |
||
16 | */ |
||
17 | class CreateDataObjectCommand extends Command |
||
18 | { |
||
19 | const ARGUMENTS_NAME = 'name'; |
||
20 | const ARGUMENTS_NAMESPACE = 'namespace'; |
||
21 | const ARGUMENTS_PATH = 'path'; |
||
22 | const OPTIONS_HAS_ONE = 'withHasOne'; |
||
23 | const OPTIONS_HAS_MANY = 'withHasMany'; |
||
24 | const OPTIONS_MANY_MANY = 'withManyMany'; |
||
25 | const OPTIONS_TRADITIONAL_ARRAY = 'withTraditionalArray'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
![]() |
|||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $namespace; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $modulePath; |
||
41 | |||
42 | /** |
||
43 | * @var Filesystem |
||
44 | */ |
||
45 | private $fileSystem; |
||
46 | |||
47 | /** |
||
48 | * @var string The target frameowkr version |
||
49 | */ |
||
50 | private $frameworkVersion = 'ss4'; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $separator = DIRECTORY_SEPARATOR; |
||
56 | |||
57 | /** |
||
58 | * Whether or not to use traditional array syntax |
||
59 | * @var bool |
||
60 | */ |
||
61 | private $useTraditionalArraySyntax = false; |
||
62 | |||
63 | /** |
||
64 | * Configures the command |
||
65 | */ |
||
66 | View Code Duplication | protected function configure() |
|
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. ![]() |
|||
67 | { |
||
68 | $this->setName('create-dataobject') |
||
69 | ->setDescription('Sets up a new SilverStripe dataobject skeleton at the' |
||
70 | . ' given path.') |
||
71 | ->addArgument(self::ARGUMENTS_NAME, InputArgument::REQUIRED) |
||
72 | ->addArgument(self::ARGUMENTS_PATH, InputArgument::REQUIRED) |
||
73 | ->addArgument(self::ARGUMENTS_NAMESPACE, InputArgument::REQUIRED) |
||
74 | ->addOption(self::OPTIONS_HAS_ONE, null, InputOption::VALUE_NONE) |
||
75 | ->addOption(self::OPTIONS_HAS_MANY, null, InputOption::VALUE_NONE) |
||
76 | ->addOption(self::OPTIONS_MANY_MANY, null, InputOption::VALUE_NONE) |
||
77 | ->addOption(self::OPTIONS_TRADITIONAL_ARRAY, null, InputOption::VALUE_NONE); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Executes this command |
||
82 | * @param InputInterface $input |
||
83 | * @param OutputInterface $output |
||
84 | * @return int|null|void |
||
85 | */ |
||
86 | protected function execute(InputInterface $input, OutputInterface $output) |
||
87 | { |
||
88 | $this->setArguments($input); |
||
89 | $output->writeln( |
||
90 | "Creating SilverStripe DataObject named {$this->name} " |
||
91 | . "at {$this->modulePath}" |
||
92 | ); |
||
93 | $this->preCopyOptions($input); |
||
94 | $this->copySkeleton(); |
||
95 | $output->writeln(' - Skeleton created'); |
||
96 | $this->postCopyOptions($input); |
||
97 | $output->writeln(' - Options applied'); |
||
98 | $output->writeln(' - Done'); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Sets the argument values to their respective properties |
||
103 | * @param InputInterface $input |
||
104 | * @throws RuntimeException |
||
105 | */ |
||
106 | View Code Duplication | protected function setArguments(InputInterface $input) |
|
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. ![]() |
|||
107 | { |
||
108 | $this->name = $input->getArgument(self::ARGUMENTS_NAME); |
||
109 | $this->namespace = $input->getArgument(self::ARGUMENTS_NAMESPACE); |
||
110 | $this->modulePath = $input->getArgument(self::ARGUMENTS_PATH); |
||
111 | |||
112 | ValidationHelper::validateNamespace($this->namespace); |
||
113 | ValidationHelper::validateModuleName($this->moduleName); |
||
0 ignored issues
–
show
The property
moduleName 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;
![]() |
|||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param InputInterface $input |
||
118 | */ |
||
119 | protected function preCopyOptions(InputInterface $input) |
||
120 | { |
||
121 | if ($input->getOption(self::OPTIONS_TRADITIONAL_ARRAY)) { |
||
122 | $this->useTraditionalArraySyntax = true; |
||
123 | } |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Checks for and actions all actions |
||
128 | * @param InputInterface $input |
||
129 | * @param OutputInterface $output |
||
0 ignored issues
–
show
There is no parameter named
$output . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
130 | */ |
||
131 | protected function postCopyOptions(InputInterface $input) |
||
132 | { |
||
133 | $source = $this->getSourcePath('options'); |
||
134 | $target = $this->getTargetPath(); |
||
135 | $uri = function ($folder, $endPoint) { |
||
136 | return "{$folder}{$this->separator}{$endPoint}"; |
||
137 | }; |
||
138 | if ($input->getOption(self::OPTIONS_HAS_ONE)) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
139 | // $this->moduleType = 'silverstripe-module'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
45% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
140 | } |
||
141 | |||
142 | if ($ss3 = $input->getOption(self::OPTIONS_SS3)) { |
||
0 ignored issues
–
show
$ss3 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
143 | $this->frameworkVersion = 'ss3'; |
||
144 | } |
||
145 | |||
146 | View Code Duplication | if ($withTravis = $input->getOption(self::OPTIONS_HAS_MANY)) { |
|
0 ignored issues
–
show
$withTravis is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() This code seems to be duplicated across 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. ![]() |
|||
147 | $file = '.travis.yml'; |
||
148 | $this->getFilesystem()->copy( |
||
149 | $uri($source, $file), |
||
150 | $uri($target, $file) |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | View Code Duplication | if ($withCircleCI = $input->getOption(self::OPTIONS_MANY_MANY)) { |
|
0 ignored issues
–
show
$withCircleCI is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() This code seems to be duplicated across 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. ![]() |
|||
155 | $folder = '.circleci'; |
||
156 | $this->getFilesystem()->mirror( |
||
157 | $uri($source, $folder), |
||
158 | $uri($target, $folder) |
||
159 | ); |
||
160 | } |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Copies the skeleton to the root directory |
||
165 | */ |
||
166 | protected function copySkeleton() |
||
167 | { |
||
168 | $this->getFilesystem()->mirror( |
||
169 | $this->getSourcePath(), |
||
170 | $this->getTargetPath() |
||
171 | ); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Copies the configured values to the composer.json file |
||
176 | */ |
||
177 | protected function setupComposerJson() |
||
178 | { |
||
179 | $path = $this->getTargetPath() . DIRECTORY_SEPARATOR . 'composer.json'; |
||
180 | $contents = file_get_contents($path); |
||
181 | $search = [ |
||
182 | '$moduleName', |
||
183 | '$namespace' |
||
184 | ]; |
||
185 | $replace = [ |
||
186 | $this->name, |
||
187 | $this->namespace |
||
188 | ]; |
||
189 | |||
190 | $contents = str_ireplace($search, $replace, $contents); |
||
191 | $this->getFilesystem()->dumpFile($path, $contents); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Gets or sets the file system property |
||
196 | * @return Filesystem |
||
197 | */ |
||
198 | protected function getFilesystem() |
||
199 | { |
||
200 | if (!$this->fileSystem) { |
||
201 | $this->fileSystem = new Filesystem(); |
||
202 | } |
||
203 | |||
204 | return $this->fileSystem; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Returns the path to the given sub-dir. Defaults to assets skeleton |
||
209 | * @param string $subDir |
||
210 | * @return string |
||
211 | */ |
||
212 | protected function getSourcePath($subDir = 'assets') |
||
213 | { |
||
214 | $porterDir = __DIR__; |
||
215 | return "{$porterDir}{$this->separator}{$subDir}{$this->separator}{$this->frameworkVersion}-dataobject"; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * Gets destination path for the module skeleton |
||
220 | * @return string |
||
221 | */ |
||
222 | protected function getTargetPath() |
||
223 | { |
||
224 | $folderName = substr($this->name, stripos($this->name, DIRECTORY_SEPARATOR) + 1); |
||
225 | return $this->modulePath . $this->separator . $folderName; |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @return bool |
||
230 | */ |
||
231 | public function isTraditionalSyntax() |
||
232 | { |
||
233 | return $this->useTraditionalArraySyntax; |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * @param bool $traditionalSyntax |
||
238 | * @return CreateDataObjectCommand |
||
239 | */ |
||
240 | public function setTraditionalSyntax($traditionalSyntax) |
||
241 | { |
||
242 | $this->useTraditionalArraySyntax = $traditionalSyntax; |
||
243 | return $this; |
||
244 | } |
||
245 | } |
||
246 |