Issues (47)

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/Str/Str.php (9 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
 * Part of twLib
4
 * http://www.thomaswhiston.com
5
 * [email protected]
6
 * Created by PhpStorm.
7
 * User: Thomas Whiston
8
 * Date: 11/12/2015
9
 * Time: 23:39
10
 * Part of twLib
11
 * http://www.thomaswhiston.com
12
 */
13
namespace twhiston\twLib\Str;
14
15
/**
16
 * Class Str
17
 * String helper functions
18
 * @package twhiston\twLib
19
 */
20
class Str
21
{
22
23
    /**
24
     * Does the string start with?
25
     * @param $haystack
26
     * @param $needles
27
     * @return bool|string if an array is passed in the matching string will be returned, else true/false
28
     */
29 5
    static public function startsWith($haystack, $needles)
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
30
    {
31 5
        if ($haystack === null) {
32
            return false;
33
        }
34 5
        if (is_array($needles)) {
35 3
            foreach ((array)$needles as $needle) {
36 3
                if ($needle != '' && strpos($haystack, $needle) === 0) {
37 1
                    return $needle;
38
                }
39 3
            }
40 3
        } else {
41 3
            if ($needles != '' && strpos($haystack, $needles) === 0) {
42 2
                return true;
43
            }
44
        }
45
46 5
        return false;
47
    }
48
49
    /**
50
     * Does the string end with?
51
     * @param $haystack
52
     * @param $needles
53
     * @return array|bool if an array is passed in the matching string will be returned, else true/false
54
     */
55 3
    static public function endsWith($haystack, $needles)
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
56
    {
57 3
        if ($haystack === null) {
58
            return false;
59
        }
60 3
        if (is_array($needles)) {
61 1
            foreach ((array)$needles as $needle) {
62 1 View Code Duplication
                if (($temp = strlen($haystack) - strlen(
0 ignored issues
show
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.

Loading history...
63
                            $needle
64 1
                        )) >= 0 && strpos(
65 1
                        $haystack,
66 1
                        $needle,
67
                        $temp
68 1
                    ) !== false
69 1
                ) {
70 1
                    return $needle;
71
                }
72 1
            }
73 1 View Code Duplication
        } else {
0 ignored issues
show
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.

Loading history...
74 3
            if (($temp = strlen($haystack) - strlen($needles)) >= 0 && strpos(
75 3
                    $haystack,
76 3
                    $needles,
77
                    $temp
78 3
                ) !== false
79 3
            ) {
80 2
                return true;
81
            }
82
        }
83
84 3
        return false;
85
    }
86
87
    /**
88
     * Does the haystack contain needles? If array in will return array out or false
89
     * @param $haystack
90
     * @param $needles
91
     * @return array|bool if an array is passed in the matching string will be returned, else true/false
92
     */
93 1
    static public function contains($haystack, $needles)
0 ignored issues
show
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
94
    {
95 1
        if ($haystack === null) {
96
            return false;
97
        }
98 1
        if (is_array($needles)) {
99 1
            $results = array();
100 1
            foreach ((array)$needles as $needle) {
101 1
                if (strpos($haystack, $needle) !== false) {
102 1
                    $results[] = $needle;
103 1
                }
104 1
            }
105 1
            if (empty($results)) {
106 1
                return false;
107
            }
108
109 1
            return $results;
110
        } else {
111 1
            if (strpos($haystack, $needles) !== false) {
112 1
                return true;
113
            }
114
        }
115
116 1
        return false;
117
118
    }
119
120
    /**
121
     * Get part of a string before a phrase or array of phrases. Returns an array of results keyed by phrase
122
     * Making recursive true makes this work like tokenizing the string
123
     * You can preserve the phrase by marking the variable true
124
     * output array is in the form of
125
     * $data[$phrase][$index] where index is a numeric value
126
     * @param $string
127
     * @param $phrase string|[string]
128
     * @return array
129
     */
130 1 View Code Duplication
    static public function getBefore($string, $phrase)
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...
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
131
    {
132
133 1
        if (!is_array($phrase)) {
134 1
            $phrase = [$phrase];
135 1
        }
136
137 1
        $output = [];
138 1
        foreach ($phrase as $item) {
139 1
            $e = explode($item, $string);
140 1
            array_pop($e);//remove the rest of string entry
141 1
            $output[$item] = $e;
142 1
        }
143
144 1
        return $output;
145
146
    }
147
148
    /**
149
     * Get part of a string after a phrase or array of phrases. Returns an array of results keyed by phrase
150
     * If no instances of the key were found returns false
151
     * The last member of the array will be blank if the token is the last thing in the string
152
     * @param $string
153
     * @param $phrase string|[string]
154
     * @return array
155
     */
156 1 View Code Duplication
    static public function getAfter($string, $phrase)
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...
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
157
    {
158
159 1
        if (!is_array($phrase)) {
160 1
            $phrase = [$phrase];
161 1
        }
162
163 1
        $output = [];
164 1
        foreach ($phrase as $item) {
165 1
            $e = explode($item, $string);
166 1
            array_shift($e);//remove the first item always
167 1
            $output[$item] = $e;
168 1
        }
169
170 1
        return $output;
171
    }
172
173
}