Skip to content

Commit

Permalink
bridge: Rename listBridge to getBridgeNames
Browse files Browse the repository at this point in the history
  • Loading branch information
logmanoriginal committed Nov 15, 2018
1 parent 66b11b8 commit 88b0656
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$list->bridges = array();
$list->total = 0;

foreach(Bridge::listBridges() as $bridgeName) {
foreach(Bridge::getBridgeNames() as $bridgeName) {

$bridge = Bridge::create($bridgeName);

Expand Down
28 changes: 14 additions & 14 deletions lib/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,29 @@ public static function isBridgeName($name){
}

/**
* Returns the list of bridge names based on the working directory.
* Returns the list of bridge names from the working directory.
*
* The list is cached internally to allow for successive calls.
*
* @return array List of bridge names
*/
public static function listBridges(){
public static function getBridgeNames(){

static $listBridge = array(); // Initialized on first call
static $bridgeNames = array(); // Initialized on first call

if(empty($listBridge)) {
$dirFiles = scandir(self::getWorkingDir());
if(empty($bridgeNames)) {
$files = scandir(self::getWorkingDir());

if($dirFiles !== false) {
foreach($dirFiles as $fileName) {
if(preg_match('/^([^.]+)Bridge\.php$/U', $fileName, $out)) {
$listBridge[] = $out[1];
if($files !== false) {
foreach($files as $file) {
if(preg_match('/^([^.]+)Bridge\.php$/U', $file, $out)) {
$bridgeNames[] = $out[1];
}
}
}
}

return $listBridge;
return $bridgeNames;
}

/**
Expand Down Expand Up @@ -218,7 +218,7 @@ public static function getWhitelist() {
$contents = trim(file_get_contents(WHITELIST));

if($contents === '*') { // Whitelist all bridges
self::$whitelist = self::listBridges();
self::$whitelist = self::getBridgeNames();
} else {
self::$whitelist = array_map('self::sanitizeBridgeName', explode("\n", $contents));
}
Expand Down Expand Up @@ -281,9 +281,9 @@ protected static function sanitizeBridgeName($name) {
}

// The name is valid if a corresponding bridge file is found on disk
if(in_array(strtolower($name), array_map('strtolower', self::listBridges()))) {
$index = array_search(strtolower($name), array_map('strtolower', self::listBridges()));
return self::listBridges()[$index];
if(in_array(strtolower($name), array_map('strtolower', self::getBridgeNames()))) {
$index = array_search(strtolower($name), array_map('strtolower', self::getBridgeNames()));
return self::getBridgeNames()[$index];
}

Debug::log('Invalid bridge name specified: "' . $name . '"!');
Expand Down
2 changes: 1 addition & 1 deletion lib/BridgeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static function getBridges($showInactive, &$totalBridges, &$totalActiveB
$totalActiveBridges = 0;
$inactiveBridges = '';

$bridgeList = Bridge::listBridges();
$bridgeList = Bridge::getBridgeNames();
$formats = Format::searchInformation();

$totalBridges = count($bridgeList);
Expand Down
4 changes: 2 additions & 2 deletions tests/BridgeImplementationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testBridgeImplementation($bridgeName){
}

public function count() {
return count(Bridge::listBridges());
return count(Bridge::getBridgeNames());
}

public function run(TestResult $result = null) {
Expand All @@ -150,7 +150,7 @@ public function run(TestResult $result = null) {
$result = new TestResult;
}

foreach (Bridge::listBridges() as $bridge) {
foreach (Bridge::getBridgeNames() as $bridge) {

$bridge .= 'Bridge';

Expand Down

0 comments on commit 88b0656

Please sign in to comment.