Skip to content

Commit

Permalink
Made suggested updates from vimeo/psalm static analysis tool
Browse files Browse the repository at this point in the history
  • Loading branch information
enobrev committed Jan 24, 2018
1 parent 10c8961 commit 18b5e03
Show file tree
Hide file tree
Showing 10 changed files with 1,633 additions and 599 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
]
},
"require-dev": {
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^5.7",
"vimeo/psalm": "^0"
}
}
2,080 changes: 1,538 additions & 542 deletions composer.lock

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<psalm
name="Example Psalm config with recommended defaults"
stopOnFirstError="false"
useDocblockTypes="true"
totallyTyped="false"
>
<projectFiles>
<directory name="src" />
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->
<DeprecatedMethod errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<UntypedParam errorLevel="info" />
</issueHandlers>
</psalm>
5 changes: 3 additions & 2 deletions src/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @return DateTime
*/
function notNowByRightNow() {
$aMicroTime = explode(' ', microtime());
return new DateTime(date('Y-m-d H:i:s.' . $aMicroTime[0] * 1000000, $aMicroTime[1]));
$aMicroTime = explode(' ', microtime());
$iMicroSeconds = (int) $aMicroTime[0] * 1000000;
return new DateTime(date('Y-m-d H:i:s.' . $iMicroSeconds, (int) $aMicroTime[1]));
}
6 changes: 3 additions & 3 deletions src/Debugging.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* @param $sMessage
*/
function _output($sMessage) {
function _output($sMessage): void {
if (isCli() || contentTypeIsNotHtml()) {
$sMessage = str_replace('<br />', "\n", $sMessage);
$sMessage = str_replace('<pre>', '', $sMessage);
Expand All @@ -14,7 +14,7 @@ function _output($sMessage) {
echo $sMessage;
}

function dbg(...$aArgs) {
function dbg(...$aArgs): void {
$sTitle = '';

if (count($aArgs) > 1) {
Expand All @@ -33,7 +33,7 @@ function dbg(...$aArgs) {
foreach ($aArgs as $mArg) {
if (is_object($mArg)
|| is_array($mArg)) {
_output('<pre>' . print_r($mArg, 1) . '</pre>');
_output('<pre>' . print_r($mArg, true) . '</pre>');
} else {
_output($mArg . "<br />");
}
Expand Down
4 changes: 2 additions & 2 deletions src/ErrorsToExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* http://us3.php.net/manual/en/function.set-error-handler.php#112881
* throw exceptions based on E_* error types
*/
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context)
set_error_handler(function (int $err_severity, string $err_msg, string $err_file, int $err_line, array $err_context): void
{
// error was suppressed with the @-operator
if (0 === error_reporting()) { return false;}
if (0 === error_reporting()) { return; }
switch($err_severity)
{
case E_ERROR: throw new ErrorException ($err_msg, 0, $err_severity, $err_file, $err_line);
Expand Down
10 changes: 7 additions & 3 deletions src/Inflect.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
// Added rule for *us -> *uses

class Inflect {
/** @var array */
static $plural = [
'/(quiz)$/i' => "$1zes",
'/^(ox)$/i' => "$1en",
Expand All @@ -80,6 +81,7 @@ class Inflect {
'/$/' => "s"
];

/** @var array */
static $singular = [
'/(quiz)zes$/i' => "$1",
'/(matr)ices$/i' => "$1ix",
Expand Down Expand Up @@ -111,6 +113,7 @@ class Inflect {
'/s$/i' => ""
];

/** @var array */
static $irregular = [
'move' => 'moves',
'foot' => 'feet',
Expand All @@ -123,6 +126,7 @@ class Inflect {
'valve' => 'valves'
];

/** @var array */
static $uncountable = [
'sheep',
'fish',
Expand All @@ -136,7 +140,7 @@ class Inflect {
'equipment'
];

public static function pluralize($string) {
public static function pluralize(string $string): string {
// save some time in the case that singular and plural are the same
if (in_array(strtolower($string), self::$uncountable)) {
return $string;
Expand All @@ -162,7 +166,7 @@ public static function pluralize($string) {
return $string;
}

public static function singularize($string) {
public static function singularize(string $string): string {
// save some time in the case that singular and plural are the same
if (in_array(strtolower($string), self::$uncountable)) {
return $string;
Expand All @@ -187,7 +191,7 @@ public static function singularize($string) {
return $string;
}

public static function pluralize_if($count, $string) {
public static function pluralize_if(int $count, string $string): string {
if ($count == 1) {
return "1 $string";
} else {
Expand Down
Loading

0 comments on commit 18b5e03

Please sign in to comment.