GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (917)

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.

src/Helpers/Strings.php (8 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
class Nip_Helper_Strings extends Nip\Helpers\AbstractHelper {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
4
    /**
5
     * Limits a string to a certain number of words
6
     *
7
     * @param string $string
8
     * @param int $limit
9
     * @param string $end
10
     * @return string
11
     */
12
    public function limitWords($string, $limit = false, $end = '...') {
13
        $words = explode(" ", $string);
14
        
15
        if (count($words) <= $limit) {
16
            return $string;
17
        }
18
19
        $return = [];
20
        for ($i = 0; $i < $limit; $i++) {
21
            $return[] = $words[$i];
22
        }
23
24
        $return[] = $end;
25
26
        return implode(" ", $return);
27
    }
28
29
30
    /**
31
     * Injects GET params in links
32
     * 
33
     * @param string $string
34
     * @param array $params
35
     * @return string
36
     */
37
    public function injectParams($string, $params = array()) {
38
        $links = preg_split('#(<a\b[^>]+>)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
39
        $old   = $links;
40
41
        foreach ($links as &$match) {
42
            if (preg_match('/<a\b/', $match) && !preg_match('/(?:#|mailto)/', $match)) {
43
                preg_match('/^([^"]+")([^"]+)/', $match, $matches);
44
                if ($matches) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $matches of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
45
                    $link = html_entity_decode($matches[2]);
46
                    if (strpos($link, "?") === false) {
47
                        $link .= "?";
48
                    } else {
49
                        $link .= "&";
50
                    }
51
52
                    $link .= http_build_query($params);
53
54
                    $match = str_replace($matches[2], $link, $match);
55
                }
56
            }
57
        }
58
59
        $string = str_replace($old, $links, $string);
60
        return $string;
61
    }
62
63
64
    /**
65
     * Converts all relative hrefs and image srcs to absolute
66
     *
67
     * @param string $string
68
     * @param string $base
69
     * @return string
70
     */
71
    public function relativeToAbsolute($string, $base) {
72
        $matches = preg_split('#(<(a|img)\b[^>]+>)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
73
        $old     = $matches;
74
75
        foreach ($matches as &$match) {
76
            if (preg_match('/<(a|img)\b/', $match) && !preg_match('/(?:http|#|mailto)/', $match)) {
77
                $match = preg_replace('/^([^"]+")([^"]+)/', '$1'.$base.'$2', $match);
78
            }
79
        }
80
81
        $string = str_replace($old, $matches, $string);
82
        return $string;
83
    }
84
85
	public function moneyFormat($number)
86
	{
87
		return money_format('%n', $number);
88
	}
89
	
90
	public function cronoTimeInSeconds($time)
91
	{
92
		$parts = explode(':', $time);		
93
		$seconds = array_pop($parts);
94
		$minutes = array_pop($parts);
95
		$hours = array_pop($parts);
96
		$days = array_pop($parts);
97
98
		return (($days*24 + $hours)*60 + $minutes)*60 + $seconds;		
99
	}
100
	
101
	public function secondsInCronoTime($seconds)
102
	{
103 View Code Duplication
		if ($days = intval((floor($seconds / 86400)))) {
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...
104
            $seconds = $seconds - $days*86400;
105
			$return .= ($return ? ':' : '') . str_pad($days, 2, 0,STR_PAD_LEFT);
0 ignored issues
show
The variable $return does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
106
		}
107 View Code Duplication
		if ($hours = intval((floor($seconds / 3600))) OR $return) {
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...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
108
            $seconds = $seconds - $hours*3600;
109
			$return .= ($return ? ':' : '') . str_pad($hours, 2, 0,STR_PAD_LEFT);
110
		}
111 View Code Duplication
		if ($minutes = intval((floor($seconds / 60))) OR $return) {
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...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
112
			$seconds = $seconds - $minutes*60;
113
			$return .= ($return ? ':' : '') . str_pad($minutes, 2, 0, STR_PAD_LEFT);
114
		}
115
		$seconds = round($seconds, 2);  
116
		$return .= ($return ? ':' : '') . str_pad($seconds, 2, 0, STR_PAD_LEFT);
117
			
118
		return $return;
119
	}
120
}