Skip to content

Commit

Permalink
Merge pull request #24 from artoroz/master
Browse files Browse the repository at this point in the history
Added phpstan and fixed issues till level 6
  • Loading branch information
kevinkhill authored Mar 17, 2021
2 parents fe97316 + a5e9a13 commit dcb222f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ sudo: false
matrix:
fast_finish: true
include:
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
- php: 8.0

branches:
only:
Expand All @@ -36,6 +34,7 @@ before_script:

script:
- composer run test
- composer run phpstan

after_script:
- php ./vendor/bin/coveralls
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"php": ">=5.4"
},
"require-dev": {
"phpstan/phpstan": "^0.12.81",
"phpunit/phpunit": "~4.8|~5.0",
"satooshi/php-coveralls": "~1.0",
"symfony/yaml": "~2.0",
Expand All @@ -38,7 +39,8 @@
}
},
"scripts": {
"test": "phpunit -c phpunit.xml"
"test": "phpunit -c phpunit.xml",
"phpstan": "vendor/bin/phpstan"
},
"minimum-stability": "stable"
}
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 6
paths:
- src
55 changes: 45 additions & 10 deletions src/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,61 @@

class Duration
{
/**
* @var int|float|null
*/
public $days;

/**
* @var int|float|null
*/
public $hours;

/**
* @var int|float|null
*/
public $minutes;

/**
* @var int|float|null
*/
public $seconds;

/**
* @var int|null
*/
public $hoursPerDay;

/**
* @var string|int
*/
private $output;

/**
* @var string
*/
private $daysRegex;

/**
* @var string
*/
private $hoursRegex;

/**
* @var string
*/
private $minutesRegex;

/**
* @var string
*/
private $secondsRegex;

/**
* Duration constructor.
*
* @param int|float|string|null $duration
* @param int $hoursPerDay
*/
public function __construct($duration = null, $hoursPerDay = 24)
{
Expand Down Expand Up @@ -60,8 +98,8 @@ public function parse($duration)

// count current precision
$precision = 0;
if (($delimiterPos = strpos($this->seconds, '.')) !== false) {
$precision = strlen(substr($this->seconds, $delimiterPos + 1));
if (($delimiterPos = strpos((string)$this->seconds, '.')) !== false) {
$precision = strlen(substr((string)$this->seconds, $delimiterPos + 1));
}

$this->seconds = (float)round(($this->seconds - ($this->minutes * 60)), $precision);
Expand Down Expand Up @@ -263,7 +301,11 @@ public function humanize($duration = null)
}


private function numberBreakdown($number, $returnUnsigned = false)
/**
* @param float $number
* @return array|float[]|int[]
*/
private function numberBreakdown($number)
{
$negative = 1;

Expand All @@ -272,13 +314,6 @@ private function numberBreakdown($number, $returnUnsigned = false)
$number *= -1;
}

if ($returnUnsigned) {
return array(
floor($number),
($number - floor($number))
);
}

return array(
floor($number) * $negative,
($number - floor($number)) * $negative
Expand Down

0 comments on commit dcb222f

Please sign in to comment.