Issues (32)

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.

components/JS.php (4 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
 * 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)) {
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 getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
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);
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
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

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.

Loading history...
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.

Loading history...
145 7
        }
146 7
    }
147
}
148