SsrModule::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the BEAR.SsrModule package.
6
 *
7
 * @license http://opensource.org/licenses/MIT MIT
8
 */
9
namespace BEAR\SsrModule;
10
11
use BEAR\SsrModule\Annotation\Ssr;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, BEAR\SsrModule\Ssr.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use Koriym\Baracoa\Baracoa;
13
use Koriym\Baracoa\BaracoaInterface;
14
use Koriym\Baracoa\ExceptionHandler;
15
use Koriym\Baracoa\ExceptionHandlerInterface;
16
use Ray\Di\AbstractModule;
17
18
class SsrModule extends AbstractModule
19
{
20
    /**
21
     * @var string
22
     */
23
    private $bundleSrcBasePath;
24
25
    /**
26
     * @param string              $bundleSrcBasePath js application directory
27
     * @param AbstractModule|null $module            Module
28
     */
29 7
    public function __construct(string $bundleSrcBasePath, AbstractModule $module = null)
30
    {
31 7
        $this->bundleSrcBasePath = $bundleSrcBasePath;
32 7
        parent::__construct($module);
33 7
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 7
    protected function configure()
39
    {
40 7
        $this->bind(SsrFactoryInterface::class)->to(SsrFactory::class);
41 7
        $this->bind(BaracoaInterface::class)->toConstructor(Baracoa::class, 'bundleSrcBasePath=bundleSrcBasePath');
42 7
        $this->bind()->annotatedWith('bundleSrcBasePath')->toInstance($this->bundleSrcBasePath);
43 7
        $this->bind(ExceptionHandlerInterface::class)->to(ExceptionHandler::class);
44 7
        $this->bindInterceptor(
45 7
            $this->matcher->any(),
46 7
            $this->matcher->annotatedWith(Ssr::class),
47 7
            [SsrInterceptor::class]
48
        );
49 7
        $this->bind(\V8Js::class)->toConstructor(\V8Js::class, 'object_name=v8js_object_name,variables=v8js_variables,extensions=v8js_extensions,report_uncaught_exceptions=v8_report_uncaught_exceptions,snapshot_blob=v8js_snapshot_blob');
50 7
        $this->bind()->annotatedWith('v8js_object_name')->toInstance('');
51 7
        $this->bind()->annotatedWith('v8js_variables')->toInstance([]);
52 7
        $this->bind()->annotatedWith('v8js_extensions')->toInstance([]);
53 7
        $this->bind()->annotatedWith('v8_report_uncaught_exceptions')->toInstance(true);
54 7
        $this->bind()->annotatedWith('v8js_snapshot_blob')->toInstance('');
55 7
    }
56
}
57