Issues (225)

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.

Scaffolder/Compilers/View/IndexViewCompiler.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
namespace Scaffolder\Compilers\View;
4
5
use Illuminate\Support\Facades\File;
6
use Scaffolder\Compilers\AbstractViewCompiler;
7
use Scaffolder\Compilers\Support\FileToCompile;
8
use Scaffolder\Compilers\Support\PathParser;
9
use Scaffolder\Support\Directory;
10
11 View Code Duplication
class IndexViewCompiler extends AbstractViewCompiler
0 ignored issues
show
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: getOutputFilename, replaceAndStore
Loading history...
This class 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...
12
{
13
    /**
14
     * Compiles the index view.
15
     *
16
     * @param      $stub
17
     * @param      $modelName
18
     * @param      $modelData
19
     * @param      $scaffolderConfig
20
     * @param      $hash
21
     * @param null $extra
22
     *
23
     * @return string
24
     */
25
    public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null)
0 ignored issues
show
The parameter $extra 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...
26
    {
27
        if (File::exists(base_path('scaffolder-config/cache/view_index_' . $hash . self::CACHE_EXT)))
28
        {
29
            return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash));
30
        }
31
        else
32
        {
33
            $this->stub = $stub;
34
35
            return $this->replaceClassName($modelName)
0 ignored issues
show
The call to IndexViewCompiler::replaceClassName() has too many arguments starting with $modelName.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
36
                ->replaceBreadcrumb($modelName)
37
                ->addDatatableFields($modelName, $modelData)
38
                ->setTableHeaders($modelData)
39
                ->replaceRoutePrefix($scaffolderConfig->routing->prefix)
40
                ->store($modelName, $scaffolderConfig, $this->stub, new FileToCompile(false, $hash));
41
        }
42
    }
43
44
    /**
45
     * Store the compiled stub.
46
     *
47
     * @param               $modelName
48
     * @param               $scaffolderConfig
49
     * @param               $compiled
50
     * @param FileToCompile $fileToCompile
51
     *
52
     * @return string
53
     */
54
    protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
55
    {
56
        $folder = PathParser::parse($scaffolderConfig->paths->views) . strtolower($modelName) ;
57
        
58
        // create folder directory
59
        Directory::createIfNotExists($folder, 0755, true);
60
61
        $path = $folder  . '/index.blade.php';
62
63
        // Store in cache
64
        if ($fileToCompile->cached)
65
        {
66
            File::copy(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $path);
67
        }
68
        else
69
        {
70
            File::put(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $compiled);
71
            File::copy(base_path('scaffolder-config/cache/view_index_' . $fileToCompile->hash . self::CACHE_EXT), $path);
72
        }
73
74
        return $path;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $path; (string) is incompatible with the return type of the parent method Scaffolder\Compilers\AbstractCompiler::store of type Scaffolder\Compilers\AbstractCompiler.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
75
    }
76
77
    /**
78
     * Datatable fields.
79
     *
80
     * @param $modelName
81
     * @param $modelData
82
     *
83
     * @return $this
84
     */
85
    private function addDatatableFields($modelName, $modelData)
86
    {
87
        $fields = '';
88
        $firstIteration = true;
89
90
        foreach ($modelData->fields as $field)
91
        {
92
            if ($field->hideInListings == false)
93
            {
94
                if ($firstIteration)
95
                {
96
                    $fields .= sprintf("{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name);
97
                    $firstIteration = false;
98
                }
99
                else
100
                {
101
                    $fields .= sprintf("\t\t\t\t{ data: '%s', name: '%s' }," . PHP_EOL, $field->name, $field->name);
102
                }
103
            }
104
        }
105
106
        $this->stub = str_replace('{{datatable_fields}}', $fields, $this->stub);
107
        $this->stub = str_replace('{{datatable_url}}', ucfirst($modelName), $this->stub);
108
109
        return $this;
110
    }
111
112
    /**
113
     * Set index table headers.
114
     *
115
     * @param $modelData
116
     *
117
     * @return $this
118
     */
119
    private function setTableHeaders($modelData)
120
    {
121
        $fields = '';
122
        $firstIteration = true;
123
124
        foreach ($modelData->fields as $field)
125
        {
126
            if ($field->hideInListings == false)
127
            {
128
                if ($firstIteration)
129
                {
130
                    $fields .= sprintf("<th>%s</th>" . PHP_EOL, ucfirst($field->name));
131
                    $firstIteration = false;
132
133
                }
134
                else
135
                {
136
                    $fields .= sprintf("\t\t\t<th>%s</th>" . PHP_EOL, ucfirst($field->name));
137
                }
138
            }
139
        }
140
141
        $this->stub = str_replace('{{table_headers}}', $fields, $this->stub);
142
143
        return $this;
144
    }
145
146
    /**
147
     * Replace the prefix.
148
     *
149
     * @param $prefix
150
     *
151
     * @return $this
152
     */
153
    private function replaceRoutePrefix($prefix)
154
    {
155
        $this->stub = str_replace('{{route_prefix}}', $prefix, $this->stub);
156
157
        return $this;
158
    }
159
}