Permalink
Browse files

several BC breaking api changes (#29)

  • Loading branch information...
1 parent e5e668a commit 869b150f00452a73fd9ca1e1db1a99aff1047444 @alcohol alcohol committed on GitHub Aug 19, 2016
Showing with 37 additions and 29 deletions.
  1. +4 −0 CHANGELOG.md
  2. +3 −3 src/DataProvider.php
  3. +17 −13 src/ISO3166.php
  4. +13 −13 tests/ISO3166Test.php
View
@@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+* Changed: renamed `getBy<Identifier>` methods to `<identifier>` ([#29]).
+* Changed: renamed `getAll` to `all` ([#29]).
+* Changed: renamed `listBy` to `iterator` ([#29]).
* Changed: `ISO3166` and `DataValidator` are now `final` ([#24]).
* Changed: support for PHP 5.5.x has been dropped ([#23]).
* Changed: `get()` method has been removed ([#19]).
@@ -27,6 +30,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
[1.0.1]: https://github.com/thephpleague/iso3166/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/thephpleague/iso3166/compare/64bae4f00dbd5679b9a36c54c37af73d5deb5be1...1.0.0
+[#29]: https://github.com/thephpleague/iso3166/issues/29
[#24]: https://github.com/thephpleague/iso3166/issues/24
[#23]: https://github.com/thephpleague/iso3166/issues/23
[#19]: https://github.com/thephpleague/iso3166/issues/19
@@ -16,19 +16,19 @@
*
* @param string $alpha2
*/
- public function getByAlpha2($alpha2);
+ public function alpha2($alpha2);
/**
* Return data for given alpha3 code.
*
* @param string $alpha3
*/
- public function getByAlpha3($alpha3);
+ public function alpha3($alpha3);
/**
* Return data for given numeric code.
*
* @param string $numeric
*/
- public function getByNumeric($numeric);
+ public function numeric($numeric);
}
View
@@ -45,11 +45,11 @@ public function __construct(array $countries = [])
*
* @return array
*/
- public function getByAlpha2($alpha2)
+ public function alpha2($alpha2)
{
$this->guardAgainstInvalidAlpha2($alpha2);
- return $this->getBy(self::KEY_ALPHA2, $alpha2);
+ return $this->lookup(self::KEY_ALPHA2, $alpha2);
}
/**
@@ -65,11 +65,11 @@ public function getByAlpha2($alpha2)
*
* @return array
*/
- public function getByAlpha3($alpha3)
+ public function alpha3($alpha3)
{
$this->guardAgainstInvalidAlpha3($alpha3);
- return $this->getBy(self::KEY_ALPHA3, $alpha3);
+ return $this->lookup(self::KEY_ALPHA3, $alpha3);
}
/**
@@ -85,46 +85,48 @@ public function getByAlpha3($alpha3)
*
* @return array
*/
- public function getByNumeric($numeric)
+ public function numeric($numeric)
{
$this->guardAgainstInvalidNumeric($numeric);
- return $this->getBy(self::KEY_NUMERIC, $numeric);
+ return $this->lookup(self::KEY_NUMERIC, $numeric);
}
/**
* @api
*
* @return array
*/
- public function getAll()
+ public function all()
{
return $this->countries;
}
/**
* @api
*
- * @param string $listBy
+ * @param string $key
*
* @return \Generator
*/
- public function listBy($listBy = self::KEY_ALPHA2)
+ public function iterator($key = self::KEY_ALPHA2)
{
- if (!in_array($listBy, $keys = [self::KEY_ALPHA2, self::KEY_ALPHA3, self::KEY_NUMERIC], true)) {
+ if (!in_array($key, $keys = [self::KEY_ALPHA2, self::KEY_ALPHA3, self::KEY_NUMERIC], true)) {
throw new \DomainException(sprintf(
'Invalid value for $indexBy, got "%s", expected one of: %s',
- $listBy,
+ $key,
implode(', ', $keys)
));
}
foreach ($this->countries as $country) {
- yield $country[$listBy] => $country;
+ yield $country[$key] => $country;
}
}
/**
+ * @see \Countable.
+ *
* @internal
*
* @return int
@@ -135,6 +137,8 @@ public function count()
}
/**
+ * @see \IteratorAggregate.
+ *
* @internal
*
* @return \Generator
@@ -158,7 +162,7 @@ public function getIterator()
*
* @return array
*/
- private function getBy($key, $value)
+ private function lookup($key, $value)
{
foreach ($this->countries as $country) {
if (0 === strcasecmp($value, $country[$key])) {
View
@@ -44,7 +44,7 @@ public function testGetByAlpha2Invalid($alpha2, $expectedException, $exceptionPa
{
$this->setExpectedExceptionRegExp($expectedException, $exceptionPattern);
- $this->iso3166->getByAlpha2($alpha2);
+ $this->iso3166->alpha2($alpha2);
}
/**
@@ -70,8 +70,8 @@ public function invalidAlpha2Provider()
*/
public function testGetByAlpha2()
{
- $this->assertEquals($this->foo, $this->iso3166->getByAlpha2($this->foo[ISO3166::KEY_ALPHA2]));
- $this->assertEquals($this->bar, $this->iso3166->getByAlpha2($this->bar[ISO3166::KEY_ALPHA2]));
+ $this->assertEquals($this->foo, $this->iso3166->alpha2($this->foo[ISO3166::KEY_ALPHA2]));
+ $this->assertEquals($this->bar, $this->iso3166->alpha2($this->bar[ISO3166::KEY_ALPHA2]));
}
/**
@@ -84,7 +84,7 @@ public function testGetByAlpha3Invalid($alpha3, $expectedException, $exceptionPa
{
$this->setExpectedExceptionRegExp($expectedException, $exceptionPattern);
- $this->iso3166->getByAlpha3($alpha3);
+ $this->iso3166->alpha3($alpha3);
}
/**
@@ -110,8 +110,8 @@ public function invalidAlpha3Provider()
*/
public function testGetByAlpha3()
{
- $this->assertEquals($this->foo, $this->iso3166->getByAlpha3($this->foo[ISO3166::KEY_ALPHA3]));
- $this->assertEquals($this->bar, $this->iso3166->getByAlpha3($this->bar[ISO3166::KEY_ALPHA3]));
+ $this->assertEquals($this->foo, $this->iso3166->alpha3($this->foo[ISO3166::KEY_ALPHA3]));
+ $this->assertEquals($this->bar, $this->iso3166->alpha3($this->bar[ISO3166::KEY_ALPHA3]));
}
/**
@@ -124,7 +124,7 @@ public function testGetByNumericInvalid($numeric, $expectedException, $exception
{
$this->setExpectedExceptionRegExp($expectedException, $exceptionPattern);
- $this->iso3166->getByNumeric($numeric);
+ $this->iso3166->numeric($numeric);
}
/**
@@ -154,16 +154,16 @@ public function invalidNumericProvider()
*/
public function testGetByNumeric()
{
- $this->assertEquals($this->foo, $this->iso3166->getByNumeric($this->foo[ISO3166::KEY_NUMERIC]));
- $this->assertEquals($this->bar, $this->iso3166->getByNumeric($this->bar[ISO3166::KEY_NUMERIC]));
+ $this->assertEquals($this->foo, $this->iso3166->numeric($this->foo[ISO3166::KEY_NUMERIC]));
+ $this->assertEquals($this->bar, $this->iso3166->numeric($this->bar[ISO3166::KEY_NUMERIC]));
}
/**
* @testdox Calling getAll returns an array with all elements.
*/
public function testGetAll()
{
- $this->assertInternalType('array', $this->iso3166->getAll(), 'getAll() should return an array.');
+ $this->assertInternalType('array', $this->iso3166->all(), 'getAll() should return an array.');
}
/**
@@ -176,7 +176,7 @@ public function testIterator()
++$i;
}
- $this->assertEquals(count($this->iso3166->getAll()), $i, 'Compare iterated count to count(getAll()).');
+ $this->assertEquals(count($this->iso3166->all()), $i, 'Compare iterated count to count(getAll()).');
}
/**
@@ -185,7 +185,7 @@ public function testIterator()
public function testListBy()
{
try {
- foreach ($this->iso3166->listBy('foo') as $key => $value) {
+ foreach ($this->iso3166->iterator('foo') as $key => $value) {
// void
}
} catch (\Exception $e) {
@@ -196,7 +196,7 @@ public function testListBy()
}
$i = 0;
- foreach ($this->iso3166->listBy(ISO3166::KEY_ALPHA3) as $key => $value) {
+ foreach ($this->iso3166->iterator(ISO3166::KEY_ALPHA3) as $key => $value) {
++$i;
}

0 comments on commit 869b150

Please sign in to comment.