Issues (5)

Security Analysis    no request data  

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/FormerHelper.php (2 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 AnilcanCakir\Former;
4
5
use AnilcanCakir\Former\Contracts\FormerHelper as Contract;
6
use Illuminate\Contracts\Config\Repository as Config;
7
use Illuminate\Contracts\Routing\UrlGenerator as Url;
8
use Illuminate\Contracts\Translation\Translator;
9
use Illuminate\Contracts\View\Factory as View;
10
11
class FormerHelper implements Contract
12
{
13
    /**
14
     * @var View
15
     */
16
    protected $view;
17
18
    /**
19
     * @var Translator
20
     */
21
    protected $translator;
22
23
    /**
24
     * @var Config
25
     */
26
    protected $config;
27
28
    /**
29
     * @var Url
30
     */
31
    protected $url;
32
33
    public function __construct(View $view, Translator $translator, Config $config, Url $url)
34
    {
35
        $this->view = $view;
36
        $this->translator = $translator;
37
        $this->config = $config;
38
        $this->url = $url;
39
    }
40
41
    /**
42
     * Get view path.
43
     *
44
     * @param string|null $view
45
     * @param null $theme
46
     * @return string
47
     */
48
    public function getViewPath($view = null, $theme = null): string
49
    {
50
        // Update the theme variable
51
        $theme = $this->getThemeOrDefault($theme);
52
53
        $path = "former.{$theme}.{$view}";
54
        if ($this->view->exists($path)) {
55
            return $path;
56
        }
57
58
        return "former::{$theme}.{$view}";
59
    }
60
61
    /**
62
     * Get config value by given key.
63
     *
64
     * @param string $key
65
     * @return mixed
66
     */
67
    public function config($key)
68
    {
69
        return $this->config->get(
70
            "former.{$key}"
71
        );
72
    }
73
74
    /**
75
     * Get field class from rules.
76
     *
77
     * @param array $rules
78
     * @return string
79
     */
80 View Code Duplication
    public function getFieldClassFromRules(array $rules): string
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.

Loading history...
81
    {
82
        foreach ($this->config('fields') as $input => $types) {
83
            foreach ($rules as $rule) {
84
                if (in_array($rule, $types)) {
85
                    return $input;
86
                }
87
            }
88
        }
89
90
        return $this->config('default_field');
91
    }
92
93
    /**
94
     * Get field class from type.
95
     *
96
     * @param string $type
97
     * @return string
98
     */
99 View Code Duplication
    public function getFieldClassFromType($type): string
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.

Loading history...
100
    {
101
        foreach ($this->config('fields') as $input => $types) {
102
            if (in_array($type, $types)) {
103
                return $input;
104
            }
105
        }
106
107
        return $this->config('default_field');
108
    }
109
110
    /**
111
     * Get given theme or default theme.
112
     *
113
     * @param null|string $theme
114
     * @return string
115
     */
116
    public function getThemeOrDefault($theme = null): string
117
    {
118
        return $theme ?: $this->config('theme');
119
    }
120
121
    /**
122
     * Get url by route name.
123
     *
124
     * @param string $route
125
     * @return string
126
     */
127
    public function getUrlByRoute($route): string
128
    {
129
        return $this->url->route($route);
130
    }
131
132
    /**
133
     * Translate a given key.
134
     *
135
     * @param string $key
136
     * @return mixed|null
137
     */
138
    public function trans($key)
139
    {
140
        $trans = $trans = $this->translator->trans($key);
141
142
        return $trans != $key ? $trans : null;
143
    }
144
}
145