Skip to content

Commit

Permalink
Feature/update (#104)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
norberttech authored Jan 29, 2019
1 parent 8bff003 commit 3853fdb
Show file tree
Hide file tree
Showing 52 changed files with 809 additions and 689 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor/
bin/
composer.lock
composer.phar
composer.phar
.php_cs.cache
18 changes: 18 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'declare_strict_types' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'single_blank_line_before_namespace' => true,
'no_unused_imports' => true,
'single_quote' => true,
'native_function_invocation' => true
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
)->setRiskyAllowed(true)
->setUsingCache(false);
18 changes: 7 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@ sudo: false
cache:
directories:
- $HOME/.composer/cache

matrix:
include:
- php: 5.3
env: DEPENDENCIES='low'
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
- php: 7.1
- php: 7.2
- php: 7.3

before_install:
- composer self-update

install:
- export COMPOSER_ROOT_VERSION=dev-master
- if [ "$DEPENDENCIES" != "low" ]; then composer update; fi;
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi;
- composer update

script:
- ./bin/phpspec run --format=pretty
- ./bin/phpunit
- ./bin/phpunit
- ./bin/php-cs-fixer fix -v --dry-run
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
#PHP Humanizer
# PHP Humanizer

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

### Tests
* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=master)](https://travis-ci.org/coduo/php-humanizer) - master (3.0)
* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=2.0)](https://travis-ci.org/coduo/php-humanizer) - 2.0
* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=1.0)](https://travis-ci.org/coduo/php-humanizer) - 1.0

[Readme for master (3.0) version](https://github.com/coduo/php-humanizer/tree/master/README.md)
[Readme for 2.0 version](https://github.com/coduo/php-matcher/tree/2.0/README.md)
[Readme for 1.0 version](https://github.com/coduo/php-matcher/tree/1.0/README.md)


Humanize values to make them readable for regular people ;)

#Installation
# Installation

Run the following command:

```shell
composer require coduo/php-humanizer
```

#Usage
# Usage

## Text

Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
}
],
"require": {
"php": ">=5.3.0",
"symfony/config": "^2.3|^3.0",
"symfony/translation": "^2.3|^3.0",
"symfony/yaml": "^2.3|^3.0"
"php": ">=7.0.0",
"symfony/config": "^2.3|^3.0|^4.0",
"symfony/translation": "^2.3|^3.0|^4.0",
"symfony/yaml": "^2.3|^3.0|^4.0",
"friendsofphp/php-cs-fixer": "^2.14"
},
"require-dev": {
"thunderer/shortcode": "~0.5",
Expand All @@ -36,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
"dev-master": "3.0-dev"
}
},
"suggest": {
Expand Down
32 changes: 17 additions & 15 deletions src/Coduo/PHPHumanizer/Collection/Formatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\Collection;

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

public function format($collection, $limit = null)
{
$count = count($collection);
$count = \count($collection);

if (0 === $count) {
return '';
Expand Down Expand Up @@ -57,16 +59,16 @@ public function format($collection, $limit = null)
*/
private function formatCommaSeparatedWithLimit($collection, $limit, $count)
{
$display = array_map(function ($element) {
$display = \array_map(function ($element) {
return (string) $element;
}, array_slice($collection, 0, $limit));
}, \array_slice($collection, 0, $limit));

$moreCount = $count - count($display);
$moreCount = $count - \count($display);

return $this->translator->transChoice('comma_separated_with_limit', $moreCount, array(
'%list%' => implode(', ', $display),
return $this->translator->transChoice('comma_separated_with_limit', $moreCount, [
'%list%' => \implode(', ', $display),
'%count%' => $moreCount,
), $this->catalogue);
], $this->catalogue);
}

/**
Expand All @@ -77,14 +79,14 @@ private function formatCommaSeparatedWithLimit($collection, $limit, $count)
*/
private function formatCommaSeparated($collection, $count)
{
$display = array_map(function ($element) {
$display = \array_map(function ($element) {
return (string) $element;
}, array_slice($collection, 0, $count - 1));
}, \array_slice($collection, 0, $count - 1));

return $this->translator->trans('comma_separated', array(
'%list%' => implode(', ', $display),
'%last%' => (string) end($collection),
), $this->catalogue);
return $this->translator->trans('comma_separated', [
'%list%' => \implode(', ', $display),
'%last%' => (string) \end($collection),
], $this->catalogue);
}

/**
Expand All @@ -94,9 +96,9 @@ private function formatCommaSeparated($collection, $count)
*/
private function formatOnlyTwo($collection)
{
return $this->translator->trans('only_two', array(
return $this->translator->trans('only_two', [
'%first%' => (string) $collection[0],
'%second%' => (string) $collection[1],
), $this->catalogue);
], $this->catalogue);
}
}
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/Collection/Oxford.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\Collection;

final class Oxford
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/CollectionHumanizer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer;

use Coduo\PHPHumanizer\Collection\Formatter;
Expand Down
10 changes: 6 additions & 4 deletions src/Coduo/PHPHumanizer/DateTime/Difference.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime;

use Coduo\PHPHumanizer\DateTime\Unit\Day;
Expand Down Expand Up @@ -59,7 +61,7 @@ public function getQuantity()
private function calculate()
{
/* @var $units \Coduo\PHPHumanizer\DateTime\Unit[] */
$units = array(
$units = [
new Year(),
new Month(),
new Week(),
Expand All @@ -68,9 +70,9 @@ private function calculate()
new Minute(),
new Second(),
new JustNow(),
);
];

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

$this->quantity = ($absoluteMilliSecondsDiff == 0)
? $absoluteMilliSecondsDiff
: (int) round($absoluteMilliSecondsDiff / $this->unit->getMilliseconds());
: (int) \round($absoluteMilliSecondsDiff / $this->unit->getMilliseconds());
}

public function isPast()
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Difference;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
6 changes: 4 additions & 2 deletions src/Coduo/PHPHumanizer/DateTime/Formatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime;

use Symfony\Component\Translation\TranslatorInterface;
Expand Down Expand Up @@ -27,12 +29,12 @@ public function __construct(TranslatorInterface $translator)
*/
public function formatDifference(Difference $difference, $locale = 'en')
{
$translationKey = sprintf('%s.%s', $difference->getUnit()->getName(), $difference->isPast() ? 'past' : 'future');
$translationKey = \sprintf('%s.%s', $difference->getUnit()->getName(), $difference->isPast() ? 'past' : 'future');

return $this->translator->transChoice(
$translationKey,
$difference->getQuantity(),
array('%count%' => $difference->getQuantity()),
['%count%' => $difference->getQuantity()],
'difference',
$locale
);
Expand Down
6 changes: 4 additions & 2 deletions src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime;

use Coduo\PHPHumanizer\DateTime\Unit\Day;
Expand Down Expand Up @@ -50,14 +52,14 @@ public function getCompoundResults()
private function calculate()
{
/* @var $units \Coduo\PHPHumanizer\DateTime\Unit[] */
$units = array(
$units = [
new Year(),
new Month(),
new Day(),
new Hour(),
new Minute(),
new Second(),
);
];

$diff = $this->fromDate->diff($this->toDate);

Expand Down
8 changes: 5 additions & 3 deletions src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime;

use Symfony\Component\Translation\TranslatorInterface;
Expand Down Expand Up @@ -27,21 +29,21 @@ public function __construct(TranslatorInterface $translator)
*/
public function formatDifference(PreciseDifference $difference, $locale = 'en')
{
$diff = array();
$diff = [];

foreach ($difference->getCompoundResults() as $result) {
$diff[] = $this->translator->transChoice(
'compound.'.$result->getUnit()->getName(),
$result->getQuantity(),
array('%count%' => $result->getQuantity()),
['%count%' => $result->getQuantity()],
'difference',
$locale
);
}

return $this->translator->trans(
'compound.'.($difference->isPast() ? 'past' : 'future'),
array('%value%' => implode(', ', $diff)),
['%value%' => \implode(', ', $diff)],
'difference',
$locale
);
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime;

interface Unit
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit/Day.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Unit;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Unit;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit/JustNow.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Unit;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit/Minute.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Unit;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit/Month.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Unit;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
2 changes: 2 additions & 0 deletions src/Coduo/PHPHumanizer/DateTime/Unit/Second.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Coduo\PHPHumanizer\DateTime\Unit;

use Coduo\PHPHumanizer\DateTime\Unit;
Expand Down
Loading

0 comments on commit 3853fdb

Please sign in to comment.