Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from koriym/refactor
Bump phpstan to 1.0.2
- Loading branch information
Showing
45 changed files
with
279 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
filter: | ||
paths: ["src/*"] | ||
|
||
tools: | ||
php_sim: true | ||
php_pdepend: true | ||
php_analyzer: true | ||
build: | ||
nodes: | ||
analysis: | ||
tests: | ||
override: | ||
- php-scrutinizer-run --enable-security-analysis | ||
environment: | ||
redis: true | ||
php: | ||
pecl_extensions: | ||
- redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\QueryRepository; | ||
|
||
use BEAR\Resource\ResourceObject; | ||
use Ray\Aop\MethodInterceptor; | ||
use Ray\Aop\MethodInvocation; | ||
use Throwable; | ||
|
||
use function assert; | ||
use function get_class; | ||
use function sprintf; | ||
use function trigger_error; | ||
|
||
use const E_USER_WARNING; | ||
|
||
abstract class AbstractDonutCacheInterceptor implements MethodInterceptor | ||
{ | ||
protected const IS_ENTIRE_CONTENT_CACHEABLE = false; | ||
|
||
/** @var DonutRepositoryInterface */ | ||
private $donutRepository; | ||
|
||
public function __construct(DonutRepositoryInterface $donutRepository) | ||
{ | ||
$this->donutRepository = $donutRepository; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function invoke(MethodInvocation $invocation) | ||
{ | ||
$ro = $invocation->getThis(); | ||
assert($ro instanceof ResourceObject); | ||
try { | ||
$maybeRo = $this->donutRepository->get($ro); | ||
if ($maybeRo instanceof ResourceObject) { | ||
return $maybeRo; | ||
} | ||
} catch (Throwable $e) { // @codeCoverageIgnoreStart | ||
// when cache server is down | ||
$this->triggerWarning($e); | ||
|
||
return $invocation->proceed(); // @codeCoverageIgnoreStartEnd | ||
} | ||
|
||
/** @var ResourceObject $ro */ | ||
$ro = $invocation->proceed(); | ||
if (isset($ro->headers[Header::ETAG])) { | ||
return $ro; // donut created in ResourceObject | ||
} | ||
|
||
return static::IS_ENTIRE_CONTENT_CACHEABLE ? | ||
$this->donutRepository->putStatic($ro, null, null) : | ||
$this->donutRepository->putDonut($ro, null); | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
private function triggerWarning(Throwable $e): void | ||
{ | ||
trigger_error(sprintf('%s: %s in %s:%s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), E_USER_WARNING); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.