Completed
Pull Request — 1.x (#139)
by Nana
09:31
created

JsonSchemaModule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the BEAR.Resource package.
6
 *
7
 * @license http://opensource.org/licenses/MIT MIT
8
 */
9
namespace BEAR\Resource\Module;
10
11
use BEAR\Resource\Annotation\JsonSchema;
12
use BEAR\Resource\Interceptor\JsonSchemaInterceptor;
13
use BEAR\Resource\ResourceObject;
14
use Ray\Di\AbstractModule;
15
16
class JsonSchemaModule extends AbstractModule
17
{
18
    /**
19
     * Json-schema json file directory
20
     *
21
     * @var string
22
     */
23
    private $jsonSchemaDir;
24
25
    /**
26
     * Json-schema validator json file directory
27
     *
28
     * @var string
29
     */
30
    private $jsonValidateDir;
31
32
    public function __construct($jsonSchemaDir = '', $jsonValidateDir = '', AbstractModule $module = null)
33
    {
34
        $this->jsonSchemaDir = $jsonSchemaDir;
35
        $this->jsonValidateDir = $jsonValidateDir;
36
        parent::__construct($module);
0 ignored issues
show
Bug introduced by
It seems like $module defined by parameter $module on line 32 can also be of type object<Ray\Di\AbstractModule>; however, Ray\Di\AbstractModule::__construct() does only seem to accept null|object<self>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function configure()
43
    {
44
        $this->bind()->annotatedWith('json_schema_dir')->toInstance($this->jsonSchemaDir);
45
        $this->bind()->annotatedWith('json_validate_dir')->toInstance($this->jsonValidateDir);
46
        $this->bindInterceptor(
47
            $this->matcher->subclassesOf(ResourceObject::class),
48
            $this->matcher->annotatedWith(JsonSchema::class),
49
            [JsonSchemaInterceptor::class]
50
        );
51
    }
52
}
53