Skip to content

Commit

Permalink
Refactor some code
Browse files Browse the repository at this point in the history
  • Loading branch information
leeqvip committed Dec 22, 2020
1 parent 8a27721 commit 1da931d
Show file tree
Hide file tree
Showing 49 changed files with 2,347 additions and 2,042 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ matrix:
- php: 7.2
- php: 7.3
- php: 7.4
- php: 8.0

install:
- composer install --prefer-dist --dev --no-interaction
- composer install --prefer-dist --dev --no-interaction

script:
- mkdir -p build/logs
- vendor/bin/phpunit
- vendor/bin/phpstan
- mkdir -p build/logs
- vendor/bin/phpstan analyse
- vendor/bin/phpunit

after_script:
- travis_retry vendor/bin/php-coveralls -v
- travis_retry vendor/bin/php-coveralls -v
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ parameters:
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
tipsOfTheDay: false
level: max
level: 7
paths:
- src
- tests
8 changes: 4 additions & 4 deletions src/CachedEnforcer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Class CachedEnforcer
* wraps Enforcer and provides decision cache.
* Wraps Enforcer and provides decision cache.
*
* @author techlee@qq.com
*/
Expand Down Expand Up @@ -36,7 +36,7 @@ public function __construct(...$params)
}

/**
* determines whether to enable cache on Enforce(). When enableCache is enabled, cached result (true | false) will be returned for previous decisions.
* Determines whether to enable cache on Enforce(). When enableCache is enabled, cached result (true | false) will be returned for previous decisions.
*
* @param bool $enableCache
*/
Expand All @@ -47,7 +47,7 @@ public function enableCache(bool $enableCache): void

/**
* Enforce decides whether a "subject" can access a "object" with the operation "action", input parameters are usually: (sub, obj, act).
* if rvals is not string , ingore the cache.
* If rvals is not string , ingore the cache.
*
* @param mixed ...$rvals
*
Expand Down Expand Up @@ -81,7 +81,7 @@ public function enforce(...$rvals): bool
}

/**
* deletes all the existing cached decisions.
* Deletes all the existing cached decisions.
*/
public function invalidateCache(): void
{
Expand Down
24 changes: 12 additions & 12 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ final class Config implements ConfigContract
public $data = [];

/**
* create an empty configuration representation from file.
* Create an empty configuration representation from file.
*
* @param string $confName
*
* @return ConfigContract
* @throws CasbinException
*/
public static function newConfig(string $confName): ConfigContract
{
Expand All @@ -42,22 +43,23 @@ public static function newConfig(string $confName): ConfigContract
}

/**
* create an empty configuration representation from text.
* Create an empty configuration representation from text.
*
* @param string $text
*
* @return ConfigContract
* @throws CasbinException
*/
public static function newConfigFromText(string $text): ConfigContract
{
$c = new static();
$c = new Config();
$c->parseBuffer($text);

return $c;
}

/**
* adds a new section->key:value to the configuration.
* Adds a new section->key:value to the configuration.
*
* @param string $section
* @param string $option
Expand Down Expand Up @@ -91,9 +93,7 @@ private function parse(string $fname): bool
{
$buf = file_get_contents($fname);

$res = $this->parseBuffer($buf);

return $res;
return $buf === false ? false : $this->parseBuffer($buf);
}

/**
Expand All @@ -111,7 +111,7 @@ private function parseBuffer(string $buf): bool
$canWrite = null;

$buf = preg_replace('/[\r\n]+/', PHP_EOL, $buf);
$buf = explode(PHP_EOL, $buf);
$buf = explode(PHP_EOL, $buf == null ? "" : $buf);

for ($i = 0, $len = \count($buf); $i <= $len; ++$i) {
if ($canWrite) {
Expand Down Expand Up @@ -157,7 +157,7 @@ private function parseBuffer(string $buf): bool

/**
* @param string $section
* @param int $lineNum
* @param int $lineNum
* @param string $b
*
* @throws CasbinException
Expand All @@ -183,7 +183,7 @@ private function write(string $section, int $lineNum, string &$b): void
}

/**
* lookups up the value using the provided key and converts the value to a string.
* Lookups up the value using the provided key and converts the value to a string.
*
* @param string $key
*
Expand All @@ -195,7 +195,7 @@ public function getString(string $key): string
}

/**
* lookups up the value using the provided key and converts the value to an array of string
* Lookups up the value using the provided key and converts the value to an array of string
* by splitting the string by comma.
*
* @param string $key
Expand All @@ -213,7 +213,7 @@ public function getStrings(string $key): array
}

/**
* sets the value for the specific key in the Config.
* Sets the value for the specific key in the Config.
*
* @param string $key
* @param string $value
Expand Down
2 changes: 1 addition & 1 deletion src/Config/ConfigContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Casbin\Exceptions\CasbinException;

/**
* Interface ConfigContract.
* ConfigContract defines the behavior of a Config implementation.
*
* @author techlee@qq.com
*/
Expand Down

0 comments on commit 1da931d

Please sign in to comment.