unyx /
utils
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php namespace nyx\utils; |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Platform |
||
| 5 | * |
||
| 6 | * Utilities related to the operating system PHP is running on, retrieving information about and executing |
||
| 7 | * system processes etc. |
||
| 8 | * |
||
| 9 | * Requires: |
||
| 10 | * - Function: shell_exec() (getting the shells available on this system) |
||
| 11 | * - Function: exec() (checking whether TTY is available on this system) |
||
| 12 | * |
||
| 13 | * @package Nyx\Utils\Platform |
||
| 14 | * @version 0.1.0 |
||
| 15 | * @author Michal Chojnacki <[email protected]> |
||
| 16 | * @copyright 2012-2016 Nyx Dev Team |
||
| 17 | * @link http://docs.muyo.io/nyx/utils/platform.html |
||
| 18 | */ |
||
| 19 | class Platform |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * The traits of the Platform class. |
||
| 23 | */ |
||
| 24 | use traits\StaticallyExtendable; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Platform type constants. |
||
| 28 | */ |
||
| 29 | const TYPE_UNIX = 1; |
||
| 30 | const TYPE_WINDOWS = 2; |
||
| 31 | const TYPE_BSD = 3; |
||
| 32 | const TYPE_CYGWIN = 4; |
||
| 33 | const TYPE_DARWIN = 5; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var int The platform PHP is running on. |
||
| 37 | */ |
||
| 38 | private static $type; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var array An array of shell names and the paths to their binaries once populated or false when PHP is |
||
| 42 | * running on a system that does not support them (Windows). |
||
| 43 | */ |
||
| 44 | private static $shells; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var bool Whether this platform has the 'stty' binary (always false on Windows). |
||
| 48 | */ |
||
| 49 | private static $hasStty; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Guesses and returns the platform PHP is running on. If it can't be determined, the default |
||
| 53 | * of self::TYPE_UNIX will be returned. |
||
| 54 | * |
||
| 55 | * @return int One of the platform TYPE_ constants defined in this class. |
||
| 56 | */ |
||
| 57 | public static function getType() : int |
||
| 58 | { |
||
| 59 | // Return the cached result if it's already available. |
||
| 60 | if (null !== static::$type) { |
||
|
0 ignored issues
–
show
|
|||
| 61 | return static::$type; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 62 | } |
||
| 63 | |||
| 64 | $os = strtolower(php_uname("s")); |
||
| 65 | |||
| 66 | // Check in order of likeliness. |
||
| 67 | if (false !== strpos($os, 'unix')) { |
||
| 68 | return static::$type = self::TYPE_UNIX; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 69 | } |
||
| 70 | |||
| 71 | if (0 === strpos($os, 'win')) { |
||
| 72 | return static::$type = self::TYPE_WINDOWS; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 73 | } |
||
| 74 | |||
| 75 | if (false !== strpos($os, 'bsd')) { |
||
| 76 | return static::$type = self::TYPE_BSD; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 77 | } |
||
| 78 | |||
| 79 | if (false !== strpos($os, 'darwin')) { |
||
| 80 | return static::$type = self::TYPE_DARWIN; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 81 | } |
||
| 82 | |||
| 83 | if (false !== strpos($os, 'cygwin')) { |
||
| 84 | return static::$type = self::TYPE_CYGWIN; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 85 | } |
||
| 86 | |||
| 87 | // Use the default otherwise. |
||
| 88 | return static::$type = self::TYPE_UNIX; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Checks whether PHP is running on a Unix platform |
||
| 93 | * |
||
| 94 | * @return bool True when PHP is running on a Unix platform, false otherwise. |
||
| 95 | */ |
||
| 96 | View Code Duplication | public static function isUnix() : bool |
|
| 97 | { |
||
| 98 | // Return the cached result if it's already available. |
||
| 99 | if (null !== static::$type) { |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 100 | return static::$type === self::TYPE_UNIX; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 101 | } |
||
| 102 | |||
| 103 | return static::getType() === self::TYPE_UNIX; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Checks whether PHP is running on a Windows platform |
||
| 108 | * |
||
| 109 | * @return bool True when PHP is running on a Windows platform, false otherwise. |
||
| 110 | */ |
||
| 111 | View Code Duplication | public static function isWindows() : bool |
|
| 112 | { |
||
| 113 | // Return the cached result if it's already available. |
||
| 114 | if (null !== static::$type) { |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 115 | return static::$type === self::TYPE_WINDOWS; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 116 | } |
||
| 117 | |||
| 118 | return static::getType() === self::TYPE_WINDOWS; |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Checks whether PHP is running on a BSD platform |
||
| 123 | * |
||
| 124 | * @return bool True when PHP is running on a BSD platform, false otherwise. |
||
| 125 | */ |
||
| 126 | View Code Duplication | public static function isBsd() : bool |
|
| 127 | { |
||
| 128 | // Return the cached result if it's already available. |
||
| 129 | if (null !== static::$type) { |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 130 | return static::$type === self::TYPE_BSD; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 131 | } |
||
| 132 | |||
| 133 | return static::getType() === self::TYPE_BSD; |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Checks whether PHP is running on a Darwin platform |
||
| 138 | * |
||
| 139 | * @return bool True when PHP is running on a Darwin platform, false otherwise. |
||
| 140 | */ |
||
| 141 | View Code Duplication | public static function isDarwin() : bool |
|
| 142 | { |
||
| 143 | // Return the cached result if it's already available. |
||
| 144 | if (null !== static::$type) { |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 145 | return static::$type === self::TYPE_DARWIN; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 146 | } |
||
| 147 | |||
| 148 | return static::getType() === self::TYPE_DARWIN; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Checks whether PHP is running on a Cygwin platform |
||
| 153 | * |
||
| 154 | * @return bool True when PHP is running on a Cygwin platform, false otherwise. |
||
| 155 | */ |
||
| 156 | View Code Duplication | public static function isCygwin() : bool |
|
| 157 | { |
||
| 158 | // Return the cached result if it's already available. |
||
| 159 | if (null !== static::$type) { |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 160 | return static::$type === self::TYPE_CYGWIN; |
||
|
0 ignored issues
–
show
Since
$type is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $type to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 161 | } |
||
| 162 | |||
| 163 | return static::getType() === self::TYPE_CYGWIN; |
||
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Returns the path to the given shell's binary or null when it is not available. |
||
| 168 | * |
||
| 169 | * @param string $name |
||
| 170 | * @return string|null |
||
| 171 | */ |
||
| 172 | public static function getShell(string $name) |
||
| 173 | { |
||
| 174 | return static::getShells()[$name] ?? null; |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Checks whether a shell of the given name is available in the system. |
||
| 179 | * |
||
| 180 | * @param string $name |
||
| 181 | * @return bool |
||
| 182 | */ |
||
| 183 | public static function hasShell(string $name) : bool |
||
| 184 | { |
||
| 185 | return isset(static::getShells()[$name]); |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Returns an array of shell names and the paths to their binaries once populated. Will return an empty |
||
| 190 | * array on unsupported platforms (Windows). |
||
| 191 | * |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | public static function getShells() : array |
||
| 195 | { |
||
| 196 | // Return the cached result if it's already available. |
||
| 197 | if (static::$shells !== null) { |
||
|
0 ignored issues
–
show
Since
$shells is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $shells to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 198 | return static::$shells; |
||
|
0 ignored issues
–
show
Since
$shells is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $shells to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 199 | } |
||
| 200 | |||
| 201 | // Ensure this method will be ran once at most. |
||
| 202 | static::$shells = []; |
||
|
0 ignored issues
–
show
Since
$shells is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $shells to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 203 | |||
| 204 | // Can't easily check on Windows even if Cygwin or the likes are available. |
||
| 205 | if (static::isWindows()) { |
||
| 206 | return static::$shells; |
||
|
0 ignored issues
–
show
Since
$shells is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $shells to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 207 | } |
||
| 208 | |||
| 209 | if (file_exists($file = '/etc/shells')) { |
||
| 210 | $cat = trim(shell_exec('cat '.$file.' 2> /dev/null')); |
||
| 211 | |||
| 212 | foreach (explode(PHP_EOL, $cat) as $path) { |
||
| 213 | // Ignore this line if it doesn't begin with a filepath. |
||
| 214 | if ($path[0] != '/') { |
||
| 215 | continue; |
||
| 216 | } |
||
| 217 | |||
| 218 | $name = substr($path, strrpos($path, '/') + 1); |
||
| 219 | |||
| 220 | static::$shells[$name] = $path; |
||
|
0 ignored issues
–
show
Since
$shells is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $shells to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 224 | return static::$shells; |
||
|
0 ignored issues
–
show
Since
$shells is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $shells to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Checks whether this platform has the 'stty' binary. |
||
| 229 | * |
||
| 230 | * @return bool True when 'stty' is available on this platform, false otherwise (always false on Windows). |
||
| 231 | */ |
||
| 232 | public static function hasStty() : bool |
||
| 233 | { |
||
| 234 | // Return the cached result if it's already available. |
||
| 235 | if (static::$hasStty !== null) { |
||
|
0 ignored issues
–
show
Since
$hasStty is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $hasStty to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 236 | return static::$hasStty; |
||
|
0 ignored issues
–
show
Since
$hasStty is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $hasStty to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 237 | } |
||
| 238 | |||
| 239 | // Definitely no Stty on Windows. |
||
| 240 | if (static::isWindows()) { |
||
| 241 | return static::$hasStty = false; |
||
|
0 ignored issues
–
show
Since
$hasStty is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $hasStty to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 242 | } |
||
| 243 | |||
| 244 | // Run a simple exec() call and check whether it returned with an error code. |
||
| 245 | exec('/usr/bin/env stty', $output, $exitCode); |
||
| 246 | |||
| 247 | return static::$hasStty = $exitCode === 0; |
||
|
0 ignored issues
–
show
Since
$hasStty is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $hasStty to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 248 | } |
||
| 249 | } |
||
| 250 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: