Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ matrix:
- php: 5.6
- php: 7.0
- php: hhvm
allow_failures:
- env: DEPENDENCIES='low'

before_install:
- composer self-update
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
],
"require": {
"php": ">=5.3.0",
"symfony/intl": "~2.3",
"symfony/config": "~2.3",
"symfony/translation": "~2.3",
"symfony/yaml": "~2.3",
"symfony/intl": "^2.3|^3.0",
"symfony/config": "^2.3|^3.0",
"symfony/translation": "^2.3|^3.0",
"symfony/yaml": "^2.3|^3.0",
"thunderer/shortcode": "~0.5"
},
"require-dev": {
Expand Down
20 changes: 12 additions & 8 deletions spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ function let(Translator $translator)
)->willReturn('10 minut temu');
}

function it_format_datetime_diff(Difference $diff)
function it_format_datetime_diff()
{
$diff->getUnit()->willReturn(new Minute());
$diff->getQuantity()->willReturn(10);
$diff->isPast()->willReturn(true);
$diff = new Difference(
new \DateTime("2015-01-01 00:10:00"),
new \DateTime("2015-01-01 00:00:00")
);

$this->formatDifference($diff)->shouldReturn('10 minutes ago');
}

function it_format_datetime_diff_for_specific_locale(Difference $diff)
function it_format_datetime_diff_for_specific_locale()
{
$diff->getUnit()->willReturn(new Minute());
$diff->getQuantity()->willReturn(10);
$diff->isPast()->willReturn(true);
$diff = new Difference(
new \DateTime("2015-01-01 00:10:00"),
new \DateTime("2015-01-01 00:00:00")
);

$this->formatDifference($diff, 'pl')->shouldReturn('10 minut temu');
}
}
28 changes: 11 additions & 17 deletions spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,23 @@ function let(Translator $translator)
)->willReturn('через 10 дней, 5 часов');
}

function it_format_compound_datetime_diff(PreciseDifference $diff, CompoundResult $dayResult,
CompoundResult $hourResult)
function it_format_compound_datetime_diff()
{
$dayResult->getUnit()->willReturn(new Day());
$dayResult->getQuantity()->willReturn(10);
$hourResult->getUnit()->willReturn(new Hour());
$hourResult->getQuantity()->willReturn(5);
$diff = new PreciseDifference(
new \DateTime("2015-01-01 00:00:00"),
new \DateTime("2015-01-11 05:00:00")
);

$diff->getCompoundResults()->willReturn(array($dayResult, $hourResult));
$diff->isPast()->willReturn(false);
$this->formatDifference($diff)->shouldReturn('10 days, 5 hours from now');
}

function it_format_compound_datetime_diff_for_specific_locale(PreciseDifference $diff,
CompoundResult $dayResult, CompoundResult $hourResult)
function it_format_compound_datetime_diff_for_specific_locale()
{
$dayResult->getUnit()->willReturn(new Day());
$dayResult->getQuantity()->willReturn(10);
$hourResult->getUnit()->willReturn(new Hour());
$hourResult->getQuantity()->willReturn(5);

$diff->getCompoundResults()->willReturn(array($dayResult, $hourResult));
$diff->isPast()->willReturn(false);
$diff = new PreciseDifference(
new \DateTime("2015-01-01 00:00:00"),
new \DateTime("2015-01-11 05:00:00")
);

$this->formatDifference($diff, 'ru')->shouldReturn('через 10 дней, 5 часов');
}
}
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/Collection/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Translation\TranslatorInterface;

class Formatter
final class Formatter
{
/**
* @var \Symfony\Component\Translation\TranslatorInterface
Expand Down
13 changes: 12 additions & 1 deletion src/Coduo/PHPHumanizer/Collection/Oxford.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@

namespace Coduo\PHPHumanizer\Collection;

class Oxford
final class Oxford
{
/**
* @var Formatter
*/
private $formatter;

/**
* Oxford constructor.
*
* @param Formatter $formatter
*/
public function __construct(Formatter $formatter)
{
$this->formatter = $formatter;
}

/**
* @param $collection
* @param null $limit
*
* @return string
*/
public function format($collection, $limit = null)
{
return $this->formatter->format($collection, $limit);
Expand Down
8 changes: 7 additions & 1 deletion src/Coduo/PHPHumanizer/CollectionHumanizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
use Coduo\PHPHumanizer\Collection\Oxford;
use Coduo\PHPHumanizer\Translator\Builder;

class CollectionHumanizer
final class CollectionHumanizer
{
/**
* @param $collection
* @param null $limit
* @param string $locale
* @return string
*/
public static function oxford($collection, $limit = null, $locale = 'en')
{
$oxford = new Oxford(
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Coduo\PHPHumanizer\DateTime\Unit\Week;
use Coduo\PHPHumanizer\DateTime\Unit\Year;

class Difference
final class Difference
{
/**
* @var \DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class CompoundResult
final class CompoundResult
{
/**
* @var \Coduo\PHPHumanizer\DateTime\Unit
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Translation\TranslatorInterface;

class Formatter
final class Formatter
{
/**
* @var \Symfony\Component\Translation\TranslatorInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Coduo\PHPHumanizer\DateTime\Unit\Year;
use Coduo\PHPHumanizer\DateTime\Difference\CompoundResult;

class PreciseDifference
final class PreciseDifference
{
/**
* @var \DateTime
Expand Down
6 changes: 3 additions & 3 deletions src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\Translation\TranslatorInterface;

class PreciseFormatter
final class PreciseFormatter
{
/**
* @var \Symfony\Component\Translation\TranslatorInterface
Expand All @@ -31,7 +31,7 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en')

foreach ($difference->getCompoundResults() as $result) {
$diff[] = $this->translator->transChoice(
'compound.' . $result->getUnit()->getName(),
'compound.'.$result->getUnit()->getName(),
$result->getQuantity(),
array('%count%' => $result->getQuantity()),
'difference',
Expand All @@ -40,7 +40,7 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en')
}

return $this->translator->trans(
'compound.' . ($difference->isPast() ? 'past' : 'future'),
'compound.'.($difference->isPast() ? 'past' : 'future'),
array('%value%' => implode(', ', $diff)),
'difference',
$locale
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Day implements Unit
final class Day implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Hour implements Unit
final class Hour implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/JustNow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class JustNow implements Unit
final class JustNow implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Minute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Minute implements Unit
final class Minute implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Month implements Unit
final class Month implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Second.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Second implements Unit
final class Second implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Week.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Week implements Unit
final class Week implements Unit
{
/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/DateTime/Unit/Year.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Coduo\PHPHumanizer\DateTime\Unit;

class Year implements Unit
final class Year implements Unit
{
/**
* @return string
Expand Down
14 changes: 13 additions & 1 deletion src/Coduo/PHPHumanizer/DateTimeHumanizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@
use Coduo\PHPHumanizer\DateTime\PreciseFormatter;
use Coduo\PHPHumanizer\Translator\Builder;

class DateTimeHumanizer
final class DateTimeHumanizer
{
/**
* @param \DateTime $fromDate
* @param \DateTime $toDate
* @param string $locale
* @return string
*/
public static function difference(\DateTime $fromDate, \DateTime $toDate, $locale = 'en')
{
$formatter = new Formatter(Builder::build($locale));

return $formatter->formatDifference(new Difference($fromDate, $toDate), $locale);
}

/**
* @param \DateTime $fromDate
* @param \DateTime $toDate
* @param string $locale
* @return string
*/
public static function preciseDifference(\DateTime $fromDate, \DateTime $toDate, $locale = 'en')
{
$formatter = new PreciseFormatter(Builder::build($locale));
Expand Down
8 changes: 4 additions & 4 deletions src/Coduo/PHPHumanizer/Number/Ordinal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
use Coduo\PHPHumanizer\Number\Ordinal\Builder;
use Coduo\PHPHumanizer\Number\Ordinal\StrategyInterface;

class Ordinal
final class Ordinal
{
/**
* @type int|float
* @var int|float
*/
private $number;

/**
* @type StrategyInterface
* @var StrategyInterface
*/
private $strategy;

/**
* @param int|float $number
* @param string $locale
* @param string $locale
*/
public function __construct($number, $locale)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
/**
* Tries to find a proper strategy for ordinal numbers.
*/
class Builder
final class Builder
{
/**
* @param string $locale
*
* @return StrategyInterface
*
* @throws \RuntimeException
*/
public static function build($locale)
Expand All @@ -27,7 +29,7 @@ public static function build($locale)
$strategy = "\\Coduo\\PHPHumanizer\\Resources\\Ordinal\\{$strategy}Strategy";

if (class_exists($strategy)) {
return new $strategy;
return new $strategy();
}

// Debatable: should we fallback to English?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface StrategyInterface
{
/**
* @param int|float $number
*
* @return string
*/
public function ordinalSuffix($number);
Expand Down
2 changes: 1 addition & 1 deletion src/Coduo/PHPHumanizer/Number/RomanNumeral.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Coduo\PHPHumanizer\Number;

class RomanNumeral
final class RomanNumeral
{
const MIN_VALUE = 1;
const MAX_VALUE = 3999;
Expand Down
Loading