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 | * JS.php |
||
4 | * @author Revin Roman |
||
5 | * @link https://processfast.com |
||
6 | */ |
||
7 | |||
8 | namespace processfast\yii\minify\components; |
||
9 | |||
10 | use yii\helpers\Html; |
||
11 | |||
12 | /** |
||
13 | * Class JS |
||
14 | * @package processfast\yii\minify\components |
||
15 | */ |
||
16 | class JS extends MinifyComponent |
||
17 | { |
||
18 | |||
19 | 8 | public function export() |
|
20 | { |
||
21 | 8 | $jsFiles = $this->view->jsFiles; |
|
22 | |||
23 | 8 | $jsPosition = $this->view->jsPosition; |
|
24 | 8 | $jsOptions = $this->view->jsOptions; |
|
25 | |||
26 | 8 | if (!empty($jsFiles)) { |
|
27 | 7 | foreach ($jsFiles as $position => $files) { |
|
28 | 7 | if (false === in_array($position, $jsPosition, true)) { |
|
29 | 7 | $this->view->jsFiles[$position] = []; |
|
30 | |||
31 | 7 | foreach ($files as $file => $html) { |
|
32 | 7 | $this->view->jsFiles[$position][$file] = $html; |
|
33 | 7 | } |
|
34 | 7 | } else { |
|
35 | 7 | $this->view->jsFiles[$position] = []; |
|
36 | |||
37 | 7 | $toMinify = []; |
|
38 | |||
39 | 7 | foreach ($files as $file => $html) { |
|
40 | 7 | View Code Duplication | if ($this->thisFileNeedMinify($file, $html)) { |
0 ignored issues
–
show
|
|||
41 | 7 | if ($this->view->concatJs) { |
|
42 | 7 | $toMinify[$file] = $html; |
|
43 | 7 | } else { |
|
44 | $this->process($position, $jsOptions, [$file => $html]); |
||
45 | } |
||
46 | 7 | } else { |
|
47 | 7 | if (!empty($toMinify)) { |
|
48 | $this->process($position, $jsOptions, $toMinify); |
||
49 | |||
50 | $toMinify = []; |
||
51 | } |
||
52 | |||
53 | 7 | $this->view->jsFiles[$position][$file] = $html; |
|
54 | } |
||
55 | 7 | } |
|
56 | |||
57 | 7 | if (!empty($toMinify)) { |
|
58 | 7 | $this->process($position, $jsOptions, $toMinify); |
|
59 | 7 | } |
|
60 | |||
61 | 7 | unset($toMinify); |
|
62 | } |
||
63 | 7 | } |
|
64 | 7 | } |
|
65 | 8 | } |
|
66 | |||
67 | /** |
||
68 | * @param integer $position |
||
69 | * @param array $options |
||
70 | * @param array $files |
||
71 | */ |
||
72 | 7 | protected function process($position, $options, $files) |
|
73 | { |
||
74 | 7 | $hash = $this->_getSummaryFilesHash($files) ; |
|
75 | 7 | $resultFile = sprintf('%s/%s.js', $this->view->minifyPath, $hash); |
|
76 | |||
77 | 7 | if( $this->view->S3Upload && $this->doesObjectExist( $resultFile , "JS" , $hash ) ) |
|
78 | 7 | { |
|
79 | // It exist on s3 so just get |
||
80 | $resultFile = $this->getS3Path( $resultFile , "JS" , $hash ); |
||
81 | } |
||
82 | 7 | else if (!file_exists($resultFile)) |
|
83 | 7 | { |
|
84 | 7 | $js = ''; |
|
85 | |||
86 | 7 | foreach ($files as $file => $html) { |
|
87 | 7 | $file = $this->getAbsoluteFilePath($file); |
|
88 | |||
89 | 7 | $content = ''; |
|
90 | |||
91 | 7 | if (!file_exists($file)) { |
|
92 | \Yii::warning(sprintf('Asset file not found `%s`', $file), __METHOD__); |
||
93 | 7 | } elseif (!is_readable($file)) { |
|
94 | \Yii::warning(sprintf('Asset file not readable `%s`', $file), __METHOD__); |
||
95 | } else { |
||
96 | 7 | $content .= file_get_contents($file) . ';' . "\n"; |
|
97 | } |
||
98 | |||
99 | 7 | $js .= $content; |
|
100 | 7 | } |
|
101 | |||
102 | 7 | $this->removeJsComments($js); |
|
0 ignored issues
–
show
The call to the method
processfast\yii\minify\c...\JS::removeJsComments() seems un-needed as the method has no side-effects.
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left. Let’s take a look at an example: class User
{
private $email;
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
}
If we look at the $user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.
On the hand, if we look at the $user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
// instance variable).
![]() |
|||
103 | |||
104 | 7 | if ($this->view->minifyJs) { |
|
105 | 7 | $js = (new \JSMin($js)) |
|
106 | 7 | ->min(); |
|
107 | 7 | } |
|
108 | |||
109 | 7 | if( $this->view->gzipEncodeJs ){ |
|
110 | $js = gzencode( $js , 9 ); |
||
111 | } |
||
112 | |||
113 | 7 | file_put_contents($resultFile, $js); |
|
114 | |||
115 | 7 | if (false !== $this->view->fileMode) { |
|
116 | 7 | @chmod($resultFile, $this->view->fileMode); |
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
117 | 7 | } |
|
118 | |||
119 | 7 | if( $this->view->S3Upload ) |
|
120 | 7 | { |
|
121 | $resultFile = $this->uploadToS3( $resultFile , "JS" , $hash); |
||
122 | } |
||
123 | 7 | } |
|
124 | else |
||
125 | { |
||
126 | if( $this->view->S3Upload ) |
||
127 | { |
||
128 | $resultFile = $this->uploadToS3( $resultFile , "JS" , $hash); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | 7 | $file = $this->prepareResultFile($resultFile); |
|
133 | |||
134 | 7 | $this->view->jsFiles[$position][$file] = Html::jsFile($file, $options); |
|
135 | 7 | } |
|
136 | |||
137 | /** |
||
138 | * @todo |
||
139 | * @param string $code |
||
140 | */ |
||
141 | 7 | protected function removeJsComments(&$code) |
|
0 ignored issues
–
show
|
|||
142 | { |
||
143 | 7 | if (true === $this->view->removeComments) { |
|
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. ![]() |
|||
144 | //$code = preg_replace('', '', $code); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
60% 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. ![]() |
|||
145 | 7 | } |
|
146 | 7 | } |
|
147 | } |
||
148 |
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.