Skip to content

Commit

Permalink
REFACTOR Allow Locator to be extended and config updated (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish authored Jan 29, 2020
1 parent 1de9005 commit b0bdf63
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ before_script:
script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -F php; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -F php; fi
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pipeline {

stage('Checkstyle Report') {
steps {
sh 'vendor/bin/phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=phpcs.xml.dist --extensions=php,inc --ignore=autoload.php --ignore=vendor/ src/ tests/ || exit 0'
sh 'vendor/bin/phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=phpcs.xml.dist --extensions=php,inc --ignore=autoload.php --ignore=vendor/ src/ tests/'
}
}

Expand Down Expand Up @@ -80,4 +80,4 @@ pipeline {
recordIssues enabledForFailure: true, tool: cpd(pattern: '**/logs/pmd-cpd.xml')
}
}
}
}
8 changes: 4 additions & 4 deletions src/pages/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function get_locations(
$exclude = [],
$callback = null
) {
$locationClass = Config::inst()->get(Locator::class, 'location_class');
$locationClass = Config::inst()->get(static::class, 'location_class');
$locations = $locationClass::get()->filter($filter)->exclude($exclude);

if (!empty($filterAny)) {
Expand Down Expand Up @@ -153,7 +153,7 @@ public static function locator_categories_by_locator($id = 0)
return false;
}

return Locator::get()->byID($id)->getUsedCategories();
return static::get()->byID($id)->getUsedCategories();
}

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ public function getInfoWindowTemplate()
{
return ModuleResourceLoader::singleton()->resolveURL(
Config::inst()->get(
Locator::class,
static::class,
'infoWindowTemplate'
)
);
Expand All @@ -242,7 +242,7 @@ public function getListTemplate()
{
return ModuleResourceLoader::singleton()->resolveURL(
Config::inst()->get(
Locator::class,
static::class,
'listTemplate'
)
);
Expand Down
7 changes: 4 additions & 3 deletions src/pages/LocatorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function setLocations(HTTPRequest $request = null)
}
$filter = $this->config()->get('base_filter');

$categoryVar = Config::inst()->get(Locator::class, 'category_var');
$categoryVar = $this->data()->config()->get('category_var');
if ($request->getVar($categoryVar)) {
$filter['Categories.ID'] = $request->getVar($categoryVar);
} else {
Expand All @@ -234,7 +234,8 @@ public function setLocations(HTTPRequest $request = null)
$exclude = $this->config()->get('base_exclude');
$this->extend('updateLocatorExclude', $exclude, $request);

$locations = Locator::get_locations($filter, $filterAny, $exclude);
$class = $this->data()->ClassName;
$locations = $class::get_locations($filter, $filterAny, $exclude);
$locations = DataToArrayListHelper::to_array_list($locations);

//allow for adjusting list post possible distance calculation
Expand All @@ -245,7 +246,7 @@ public function setLocations(HTTPRequest $request = null)
}

if ($this->getShowRadius()) {
$radiusVar = Config::inst()->get(Locator::class, 'radius_var');
$radiusVar = $this->data()->config()->get('radius_var');

if ($radius = (int)$request->getVar($radiusVar)) {
$locations = $locations->filterByCallback(function ($location) use (&$radius) {
Expand Down
3 changes: 1 addition & 2 deletions tests/pages/LocatorControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dynamic\Locator\Tests;

use \DOMDocument;
use Dynamic\Locator\LocationCategory;
use Dynamic\Locator\Locator;
use Dynamic\Locator\LocatorController;
Expand Down Expand Up @@ -50,7 +49,7 @@ public function testXml()
$this->assertEquals(200, $page->getStatusCode());
$this->assertEquals('application/xml', $page->getHeader('content-type'));

$dom = new DOMDocument();
$dom = new \DOMDocument();
// true if it loads, false if it doesn't
$valid = $dom->loadXML($page->getBody());
$this->assertTrue($valid);
Expand Down

0 comments on commit b0bdf63

Please sign in to comment.