Skip to content

Commit 3853fdb

Browse files
authored
Feature/update (#104)
* Updated dependencies, added php-cs-fixer * CS fixes * Fixed failing tests * Updated readme * Fixed readme * Updated branch alias * Removed prefer-lower flag from travis matrix * Updated minimum required php version
1 parent 8bff003 commit 3853fdb

52 files changed

Lines changed: 809 additions & 689 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor/
22
bin/
33
composer.lock
4-
composer.phar
4+
composer.phar
5+
.php_cs.cache

.php_cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
return PhpCsFixer\Config::create()
3+
->setRules([
4+
'@PSR2' => true,
5+
'declare_strict_types' => true,
6+
'array_syntax' => ['syntax' => 'short'],
7+
'blank_line_after_opening_tag' => true,
8+
'single_blank_line_before_namespace' => true,
9+
'no_unused_imports' => true,
10+
'single_quote' => true,
11+
'native_function_invocation' => true
12+
])
13+
->setFinder(
14+
PhpCsFixer\Finder::create()
15+
->in(__DIR__ . '/src')
16+
->in(__DIR__ . '/tests')
17+
)->setRiskyAllowed(true)
18+
->setUsingCache(false);

.travis.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,22 @@ sudo: false
55
cache:
66
directories:
77
- $HOME/.composer/cache
8-
8+
99
matrix:
1010
include:
11-
- php: 5.3
12-
env: DEPENDENCIES='low'
13-
- php: 5.3
14-
- php: 5.4
15-
- php: 5.5
16-
- php: 5.6
1711
- php: 7.0
18-
- php: hhvm
12+
- php: 7.1
13+
- php: 7.2
14+
- php: 7.3
1915

2016
before_install:
2117
- composer self-update
2218

2319
install:
2420
- export COMPOSER_ROOT_VERSION=dev-master
25-
- if [ "$DEPENDENCIES" != "low" ]; then composer update; fi;
26-
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi;
21+
- composer update
2722

2823
script:
2924
- ./bin/phpspec run --format=pretty
30-
- ./bin/phpunit
25+
- ./bin/phpunit
26+
- ./bin/php-cs-fixer fix -v --dry-run

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1-
#PHP Humanizer
1+
# PHP Humanizer
22

33
[![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=master)](https://travis-ci.org/coduo/php-humanizer)
44
[![Latest Stable Version](https://poser.pugx.org/coduo/php-humanizer/v/stable)](https://packagist.org/packages/coduo/php-humanizer)
55
[![Total Downloads](https://poser.pugx.org/coduo/php-humanizer/downloads)](https://packagist.org/packages/coduo/php-humanizer)
66
[![Latest Unstable Version](https://poser.pugx.org/coduo/php-humanizer/v/unstable)](https://packagist.org/packages/coduo/php-humanizer)
77
[![License](https://poser.pugx.org/coduo/php-humanizer/license)](https://packagist.org/packages/coduo/php-humanizer)
88

9+
### Tests
10+
* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=master)](https://travis-ci.org/coduo/php-humanizer) - master (3.0)
11+
* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=2.0)](https://travis-ci.org/coduo/php-humanizer) - 2.0
12+
* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=1.0)](https://travis-ci.org/coduo/php-humanizer) - 1.0
13+
14+
[Readme for master (3.0) version](https://github.com/coduo/php-humanizer/tree/master/README.md)
15+
[Readme for 2.0 version](https://github.com/coduo/php-matcher/tree/2.0/README.md)
16+
[Readme for 1.0 version](https://github.com/coduo/php-matcher/tree/1.0/README.md)
17+
18+
919
Humanize values to make them readable for regular people ;)
1020

11-
#Installation
21+
# Installation
1222

1323
Run the following command:
1424

1525
```shell
1626
composer require coduo/php-humanizer
1727
```
1828

19-
#Usage
29+
# Usage
2030

2131
## Text
2232

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.3.0",
19-
"symfony/config": "^2.3|^3.0",
20-
"symfony/translation": "^2.3|^3.0",
21-
"symfony/yaml": "^2.3|^3.0"
18+
"php": ">=7.0.0",
19+
"symfony/config": "^2.3|^3.0|^4.0",
20+
"symfony/translation": "^2.3|^3.0|^4.0",
21+
"symfony/yaml": "^2.3|^3.0|^4.0",
22+
"friendsofphp/php-cs-fixer": "^2.14"
2223
},
2324
"require-dev": {
2425
"thunderer/shortcode": "~0.5",
@@ -36,7 +37,7 @@
3637
},
3738
"extra": {
3839
"branch-alias": {
39-
"dev-master": "2.1-dev"
40+
"dev-master": "3.0-dev"
4041
}
4142
},
4243
"suggest": {

src/Coduo/PHPHumanizer/Collection/Formatter.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Coduo\PHPHumanizer\Collection;
46

57
use Symfony\Component\Translation\TranslatorInterface;
@@ -27,7 +29,7 @@ public function __construct(TranslatorInterface $translator, $catalogue = 'oxfor
2729

2830
public function format($collection, $limit = null)
2931
{
30-
$count = count($collection);
32+
$count = \count($collection);
3133

3234
if (0 === $count) {
3335
return '';
@@ -57,16 +59,16 @@ public function format($collection, $limit = null)
5759
*/
5860
private function formatCommaSeparatedWithLimit($collection, $limit, $count)
5961
{
60-
$display = array_map(function ($element) {
62+
$display = \array_map(function ($element) {
6163
return (string) $element;
62-
}, array_slice($collection, 0, $limit));
64+
}, \array_slice($collection, 0, $limit));
6365

64-
$moreCount = $count - count($display);
66+
$moreCount = $count - \count($display);
6567

66-
return $this->translator->transChoice('comma_separated_with_limit', $moreCount, array(
67-
'%list%' => implode(', ', $display),
68+
return $this->translator->transChoice('comma_separated_with_limit', $moreCount, [
69+
'%list%' => \implode(', ', $display),
6870
'%count%' => $moreCount,
69-
), $this->catalogue);
71+
], $this->catalogue);
7072
}
7173

7274
/**
@@ -77,14 +79,14 @@ private function formatCommaSeparatedWithLimit($collection, $limit, $count)
7779
*/
7880
private function formatCommaSeparated($collection, $count)
7981
{
80-
$display = array_map(function ($element) {
82+
$display = \array_map(function ($element) {
8183
return (string) $element;
82-
}, array_slice($collection, 0, $count - 1));
84+
}, \array_slice($collection, 0, $count - 1));
8385

84-
return $this->translator->trans('comma_separated', array(
85-
'%list%' => implode(', ', $display),
86-
'%last%' => (string) end($collection),
87-
), $this->catalogue);
86+
return $this->translator->trans('comma_separated', [
87+
'%list%' => \implode(', ', $display),
88+
'%last%' => (string) \end($collection),
89+
], $this->catalogue);
8890
}
8991

9092
/**
@@ -94,9 +96,9 @@ private function formatCommaSeparated($collection, $count)
9496
*/
9597
private function formatOnlyTwo($collection)
9698
{
97-
return $this->translator->trans('only_two', array(
99+
return $this->translator->trans('only_two', [
98100
'%first%' => (string) $collection[0],
99101
'%second%' => (string) $collection[1],
100-
), $this->catalogue);
102+
], $this->catalogue);
101103
}
102104
}

src/Coduo/PHPHumanizer/Collection/Oxford.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Coduo\PHPHumanizer\Collection;
46

57
final class Oxford

src/Coduo/PHPHumanizer/CollectionHumanizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Coduo\PHPHumanizer;
46

57
use Coduo\PHPHumanizer\Collection\Formatter;

src/Coduo/PHPHumanizer/DateTime/Difference.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Coduo\PHPHumanizer\DateTime;
46

57
use Coduo\PHPHumanizer\DateTime\Unit\Day;
@@ -59,7 +61,7 @@ public function getQuantity()
5961
private function calculate()
6062
{
6163
/* @var $units \Coduo\PHPHumanizer\DateTime\Unit[] */
62-
$units = array(
64+
$units = [
6365
new Year(),
6466
new Month(),
6567
new Week(),
@@ -68,9 +70,9 @@ private function calculate()
6870
new Minute(),
6971
new Second(),
7072
new JustNow(),
71-
);
73+
];
7274

73-
$absoluteMilliSecondsDiff = abs($this->toDate->getTimestamp() - $this->fromDate->getTimestamp()) * 1000;
75+
$absoluteMilliSecondsDiff = \abs($this->toDate->getTimestamp() - $this->fromDate->getTimestamp()) * 1000;
7476
foreach ($units as $unit) {
7577
if ($absoluteMilliSecondsDiff >= $unit->getMilliseconds()) {
7678
$this->unit = $unit;
@@ -80,7 +82,7 @@ private function calculate()
8082

8183
$this->quantity = ($absoluteMilliSecondsDiff == 0)
8284
? $absoluteMilliSecondsDiff
83-
: (int) round($absoluteMilliSecondsDiff / $this->unit->getMilliseconds());
85+
: (int) \round($absoluteMilliSecondsDiff / $this->unit->getMilliseconds());
8486
}
8587

8688
public function isPast()

src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Coduo\PHPHumanizer\DateTime\Difference;
46

57
use Coduo\PHPHumanizer\DateTime\Unit;

0 commit comments

Comments
 (0)