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

Commit

Permalink
Followup to 5df7c2e, stop loading subdivisions in the ZoneRepository.
Browse files Browse the repository at this point in the history
  • Loading branch information
bojanz committed Oct 5, 2015
1 parent d6a00e8 commit 685c49b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
24 changes: 2 additions & 22 deletions src/Repository/ZoneRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ class ZoneRepository implements ZoneRepositoryInterface
*/
protected $definitionPath;

/**
* The subdivision repository.
*
* @var SubdivisionRepositoryInterface
*/
protected $subdivisionRepository;

/**
* Zone index.
*
Expand All @@ -45,13 +38,11 @@ class ZoneRepository implements ZoneRepositoryInterface
/**
* Creates a ZoneRepository instance.
*
* @param string $definitionPath Path to the zone definitions.
* @param SubdivisionRepositoryInterface $subdivisionRepository The subdivision repository.
* @param string $definitionPath Path to the zone definitions.
*/
public function __construct($definitionPath, SubdivisionRepositoryInterface $subdivisionRepository = null)
public function __construct($definitionPath)
{
$this->definitionPath = $definitionPath;
$this->subdivisionRepository = $subdivisionRepository ?: new SubdivisionRepository();
}

/**
Expand Down Expand Up @@ -164,17 +155,6 @@ protected function createZoneFromDefinition(array $definition)
*/
protected function createZoneMemberCountryFromDefinition(array $definition)
{
// Load any referenced subdivisions.
if (isset($definition['administrative_area'])) {
$definition['administrative_area'] = $this->subdivisionRepository->get($definition['administrative_area']);
}
if (isset($definition['locality'])) {
$definition['locality'] = $this->subdivisionRepository->get($definition['locality']);
}
if (isset($definition['dependent_locality'])) {
$definition['dependent_locality'] = $this->subdivisionRepository->get($definition['dependent_locality']);
}

$zoneMember = new ZoneMemberCountry();
$setValues = \Closure::bind(function ($definition) {
$this->id = $definition['id'];
Expand Down
9 changes: 3 additions & 6 deletions tests/Repository/ZoneRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,9 @@ public function testGet($zoneRepository)
$this->assertEquals('AT', $austriaMember->getCountryCode());
$this->assertEquals('6691, 6991:6993', $austriaMember->getIncludedPostalCodes());
$this->assertEquals('123456', $austriaMember->getExcludedPostalCodes());
// Test the dummy subdivision values.
$subdivisionRepository = new SubdivisionRepository();
$subdivision = $subdivisionRepository->get('CH-AG');
$this->assertEquals($subdivision, $austriaMember->getAdministrativeArea());
$this->assertEquals($subdivision, $austriaMember->getLocality());
$this->assertEquals($subdivision, $austriaMember->getDependentLocality());
$this->assertEquals('CH-AG', $austriaMember->getAdministrativeArea());
$this->assertEquals('CH-AG', $austriaMember->getLocality());
$this->assertEquals('CH-AG', $austriaMember->getDependentLocality());

// Test the static cache.
$sameZone = $zoneRepository->get('de_vat');
Expand Down

0 comments on commit 685c49b

Please sign in to comment.