Skip to content

Commit 3a06bdd

Browse files
authored
Merge pull request #99 from koriym/refactor
Bump phpstan to 1.0.2
2 parents b4c47dc + a43170b commit 3a06bdd

45 files changed

Lines changed: 279 additions & 217 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.scrutinizer.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
filter:
2+
paths: ["src/*"]
3+
4+
tools:
5+
php_sim: true
6+
php_pdepend: true
7+
php_analyzer: true
8+
build:
9+
nodes:
10+
analysis:
11+
tests:
12+
override:
13+
- php-scrutinizer-run --enable-security-analysis
14+
environment:
15+
redis: true
16+
php:
17+
pecl_extensions:
18+
- redis

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[CQRS](http://martinfowler.com/bliki/CQRS.html) inspired **BEAR.QueryRepository** segregates reads and writes into two separate repository.
88

9-
Documentation is available at [BEAR.Sunday resource manual](http://bearsunday.github.io/manuals/1.0/en/resource.html).
9+
Documentation is available at [BEAR.Sunday cache manual](http://bearsunday.github.io/manuals/1.0/ja/cache.html).
1010

1111

1212
## Demo

dump.rdb

-92 Bytes
Binary file not shown.

phpcs.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="bearcs"
4-
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Ray.Aop coding standard"
4+
xsi:noNamespaceSchemaLocation="./vendor-bin/tools/vendor/squizlabs/php_codesniffer/phpcs.xsd">
55

66
<arg name="basepath" value="."/>
77
<arg name="extensions" value="php"/>
@@ -41,11 +41,8 @@
4141
<!-- /Base -->
4242
<!-- Option -->
4343
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
44-
<!-- attribute -->
45-
<exclude name="Squiz.WhiteSpace.FunctionSpacing.Before"/>
4644
<!-- /Option -->
4745
<!-- Exclude Fake files form Doctrine CS -->
48-
<exclude-pattern>*/tests/Fake/*</exclude-pattern>
4946
</rule>
5047

5148
<!-- Additional Rules -->
@@ -58,6 +55,15 @@
5855
</property>
5956
</properties>
6057
</rule>
58+
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
59+
<properties>
60+
<property name="annotationsGroups" type="array">
61+
<element value="@param, @psalm-param, @phpstan-param"/>
62+
<element value="@return, @psalm-return, @phpstan-return"/>
63+
<element value="@throws"/>
64+
</property>
65+
</properties>
66+
</rule>
6167
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
6268
<include-pattern>tests/*</include-pattern>
6369
</rule>

phpstan.neon

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ parameters:
1414
paths:
1515
- src
1616
- tests
17-
excludes_analyse:
17+
excludePaths:
1818
- */tests/tmp/*
1919
- */tests/Fake/*
2020
- */src/StorageRedisCacheProvider.php*
2121
ignoreErrors:
2222
-
2323
message: '#but return statement is missing#'
24-
path: tests/ResourceRepositoryTest.php
24+
path: tests/ResourceRepositoryTest.php
25+
stubFiles:
26+
- tests/stubs/Injector.phpstub
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BEAR\QueryRepository;
6+
7+
use BEAR\Resource\ResourceObject;
8+
use Ray\Aop\MethodInterceptor;
9+
use Ray\Aop\MethodInvocation;
10+
use Throwable;
11+
12+
use function assert;
13+
use function get_class;
14+
use function sprintf;
15+
use function trigger_error;
16+
17+
use const E_USER_WARNING;
18+
19+
abstract class AbstractDonutCacheInterceptor implements MethodInterceptor
20+
{
21+
protected const IS_ENTIRE_CONTENT_CACHEABLE = false;
22+
23+
/** @var DonutRepositoryInterface */
24+
private $donutRepository;
25+
26+
public function __construct(DonutRepositoryInterface $donutRepository)
27+
{
28+
$this->donutRepository = $donutRepository;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
final public function invoke(MethodInvocation $invocation)
35+
{
36+
$ro = $invocation->getThis();
37+
assert($ro instanceof ResourceObject);
38+
try {
39+
$maybeRo = $this->donutRepository->get($ro);
40+
if ($maybeRo instanceof ResourceObject) {
41+
return $maybeRo;
42+
}
43+
} catch (Throwable $e) { // @codeCoverageIgnoreStart
44+
// when cache server is down
45+
$this->triggerWarning($e);
46+
47+
return $invocation->proceed(); // @codeCoverageIgnoreStartEnd
48+
}
49+
50+
/** @var ResourceObject $ro */
51+
$ro = $invocation->proceed();
52+
if (isset($ro->headers[Header::ETAG])) {
53+
return $ro; // donut created in ResourceObject
54+
}
55+
56+
return static::IS_ENTIRE_CONTENT_CACHEABLE ?
57+
$this->donutRepository->putStatic($ro, null, null) :
58+
$this->donutRepository->putDonut($ro, null);
59+
}
60+
61+
/**
62+
* @codeCoverageIgnore
63+
*/
64+
private function triggerWarning(Throwable $e): void
65+
{
66+
trigger_error(sprintf('%s: %s in %s:%s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), E_USER_WARNING);
67+
}
68+
}

src/CacheDependency.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public function depends(ResourceObject $from, ResourceObject $to): void
2323
{
2424
assert(! isset($from->headers[Header::SURROGATE_KEY]));
2525

26-
$cacheDepedencyTags = ($this->uriTag)($to->uri);
26+
$cacheDependencyTags = ($this->uriTag)($to->uri);
2727
if (isset($to->headers[Header::SURROGATE_KEY])) {
28-
$cacheDepedencyTags .= sprintf(' %s', $to->headers[Header::SURROGATE_KEY]);
28+
$cacheDependencyTags .= sprintf(' %s', $to->headers[Header::SURROGATE_KEY]);
2929
unset($to->headers[Header::SURROGATE_KEY]);
3030
}
3131

32-
$from->headers[Header::SURROGATE_KEY] = $cacheDepedencyTags;
32+
$from->headers[Header::SURROGATE_KEY] = $cacheDependencyTags;
3333
}
3434
}

src/CacheInterceptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use const E_USER_WARNING;
1919

20-
class CacheInterceptor implements MethodInterceptor
20+
final class CacheInterceptor implements MethodInterceptor
2121
{
2222
/** @var QueryRepositoryInterface */
2323
private $repository;

src/CacheVersionModule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Ray\Di\AbstractModule;
88
use Ray\PsrCacheModule\CacheNamespaceModule;
99

10-
class CacheVersionModule extends AbstractModule
10+
final class CacheVersionModule extends AbstractModule
1111
{
1212
/** @var string */
1313
private $version;
@@ -21,7 +21,7 @@ public function __construct(string $cacheVersion, ?AbstractModule $module = null
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
protected function configure()
24+
protected function configure(): void
2525
{
2626
$this->install(new CacheNamespaceModule($this->version));
2727
}

src/CacheableModule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
1313
use Ray\Di\AbstractModule;
1414

15-
class CacheableModule extends AbstractModule
15+
final class CacheableModule extends AbstractModule
1616
{
1717
/**
1818
* {@inheritdoc}
1919
*/
20-
protected function configure()
20+
protected function configure(): void
2121
{
2222
$this->bind(HttpCacheInterface::class)->to(HttpCache::class);
2323
$this->bind()->annotatedWith(Commands::class)->toProvider(CommandsProvider::class);

0 commit comments

Comments
 (0)