Skip to content

Commit

Permalink
Change argument from collection into iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
apiotrowski committed Nov 13, 2018
1 parent 6b01af3 commit 041f528
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 85 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
},
"require": {
"php": "~7.1",
"ext-bcmath": "*",
"doctrine/collections": "^1.5"
"ext-bcmath": "*"
},
"require-dev": {
"phpunit/phpunit": "~7.4"
Expand Down
72 changes: 2 additions & 70 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 10 additions & 13 deletions src/ConvertManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UnitConverter;

use Doctrine\Common\Collections\Collection;
use UnitConverter\Converter\Converter;
use UnitConverter\Exception\NotSupportedConversionException;
use UnitConverter\Exception\NotSupportedUnitException;
Expand All @@ -23,10 +22,10 @@ class ConvertManager
private $queryResolver;

/**
* @param Converter[]|Collection $converters
* @param Converter[]|iterable $converters
* @param QueryResolver $queryResolver
*/
public function __construct(Collection $converters, QueryResolver $queryResolver)
public function __construct(iterable $converters, QueryResolver $queryResolver)
{
$this->converters = $converters;
$this->queryResolver = $queryResolver;
Expand Down Expand Up @@ -58,17 +57,15 @@ public function convert(string $rawQuery) : Value
*/
protected function getSupportedConverter(Query $query) : Converter
{
$supportedConverters = $this->converters->filter(function (Converter $converter) use ($query) {
return true === $converter->isSupported($query->getValue()->getUnit(), $query->getTargetUnit());
});

if (true === $supportedConverters->isEmpty()) {
throw new NotSupportedConversionException(
$query->getValue()->getUnit(),
$query->getTargetUnit()
);
foreach ($this->converters as $converter) {
if (true === $converter->isSupported($query->getValue()->getUnit(), $query->getTargetUnit())) {
return $converter;
}
}

return $supportedConverters->first();
throw new NotSupportedConversionException(
$query->getValue()->getUnit(),
$query->getTargetUnit()
);
}
}

0 comments on commit 041f528

Please sign in to comment.