Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from vimeo/collections-not-54-compliant
Browse files Browse the repository at this point in the history
Removing doctrine/collections because it's requires >=PHP 5.6
  • Loading branch information
erunion authored Jul 10, 2017
2 parents 247de57 + e703da0 commit df86a80
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"league/flysystem": "^1.0",
"composer/semver": "^1.4",
"gossi/docblock": "^1.5",
"nicmart/string-template": "^0.1.1",
"doctrine/collections": "^1.4"
"nicmart/string-template": "^0.1.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.7",
Expand Down
27 changes: 15 additions & 12 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
namespace Mill;

use Composer\Semver\Semver;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use DomainException;
use DOMDocument;
use InvalidArgumentException;
Expand Down Expand Up @@ -60,9 +58,9 @@ class Config
/**
* Array of API versions.
*
* @var ArrayCollection
* @var array
*/
protected $api_versions;
protected $api_versions = [];

/**
* Allowable list of valid application capabilities.
Expand Down Expand Up @@ -210,7 +208,7 @@ public static function loadFromXML(Filesystem $filesystem, $config_file, $load_b
$config->loadGeneratorSettings($xml->generators);
}

$config->api_versions = new ArrayCollection;
$config->api_versions = [];
$config->loadVersions($xml->versions->version);

$config->controllers = [];
Expand Down Expand Up @@ -425,11 +423,11 @@ protected function loadVersions(SimpleXMLElement $versions)
// Keep things tidy.
$sorted_numerical = Semver::sort(array_keys($api_versions));
foreach ($sorted_numerical as $version) {
$this->api_versions->add($api_versions[$version]);
$this->api_versions[] = $api_versions[$version];
}

$this->first_api_version = $this->api_versions->first()['version'];
$this->latest_api_version = $this->api_versions->last()['version'];
$this->first_api_version = current($this->api_versions)['version'];
$this->latest_api_version = end($this->api_versions)['version'];
}

/**
Expand Down Expand Up @@ -735,7 +733,7 @@ public function getLatestApiVersion()
/**
* Get the array of configured API versions.
*
* @return ArrayCollection
* @return array
*/
public function getApiVersions()
{
Expand All @@ -747,12 +745,17 @@ public function getApiVersions()
*
* @param string $version
* @return array
* @throws \Exception If a supplied version was not configured.
*/
public function getApiVersion($version)
{
return $this->api_versions
->matching(new Criteria(Criteria::expr()->eq('version', $version), null))
->current();
foreach ($this->api_versions as $data) {
if ($data['version'] == $version) {
return $data;
}
}

throw new \Exception('The supplied version, `' . $version . '`` was not found to be configured.');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class Generator
protected $version = null;

/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @var array
*/
protected $supported_versions;
protected $supported_versions = [];

/**
* Compiled documentation.
Expand Down
16 changes: 7 additions & 9 deletions src/Generator/Changelog.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace Mill\Generator;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Mill\Generator;
use Mill\Generator\Changelog\Json;
use Mill\Generator\Changelog\Markdown;
Expand Down Expand Up @@ -309,7 +307,7 @@ private function getVersionIntroduced(Annotation $annotation)
return false;
}

$available_in = $this->supported_versions->filter(function ($supported) use ($data_version) {
$available_in = array_filter($this->supported_versions, function ($supported) use ($data_version) {
if ($data_version->matches($supported['version'])) {
return $supported['version'];
}
Expand All @@ -318,7 +316,7 @@ private function getVersionIntroduced(Annotation $annotation)
});

// What is the first version that this existed in?
$introduced = $available_in->current()['version'];
$introduced = current($available_in)['version'];
if ($introduced === $this->config->getFirstApiVersion()) {
return false;
}
Expand All @@ -340,7 +338,7 @@ private function getVersionRemoved(Annotation $annotation)
return false;
}

$available_in = $this->supported_versions->filter(function ($supported) use ($data_version) {
$available_in = array_filter($this->supported_versions, function ($supported) use ($data_version) {
if ($data_version->matches($supported['version'])) {
return $supported['version'];
}
Expand All @@ -349,15 +347,15 @@ private function getVersionRemoved(Annotation $annotation)
});

// What is the most recent version that this was available in?
$recent_version = $available_in->last()['version'];
$recent_version = end($available_in)['version'];
if ($recent_version === $this->config->getLatestApiVersion()) {
return false;
}

$recent_version_key = key(
$this->supported_versions
->matching(new Criteria(Criteria::expr()->eq('version', $recent_version), null))
->toArray()
array_filter($this->supported_versions, function ($supported) use ($recent_version) {
return $supported['version'] == $recent_version;
})
);

return $this->supported_versions[++$recent_version_key]['version'];
Expand Down
4 changes: 1 addition & 3 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public function testLoadFromXML()
$this->assertSame('1.1.2', $config->getDefaultApiVersion());
$this->assertSame('1.1.3', $config->getLatestApiVersion());

$versions = $config->getApiVersions();
$this->assertInstanceOf('\Doctrine\Common\Collections\ArrayCollection', $versions);
$this->assertSame([
[
'version' => '1.0',
Expand All @@ -43,7 +41,7 @@ public function testLoadFromXML()
'release_date' => '2017-05-27',
'description' => 'Changed up the responses for `/movie/{id}`, `/movies/{id}` and `/movies`.'
]
], $versions->toArray());
], $config->getApiVersions());

$this->assertSame([
'FakeExcludeGroup'
Expand Down

0 comments on commit df86a80

Please sign in to comment.