ScopeFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 15
ccs 4
cts 4
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createScopeFor() 0 6 1
1
<?php namespace Pz\Doctrine\Rest\Fractal;
2
3
use League\Fractal\Manager;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pz\Doctrine\Rest\Fractal\Manager. Consider defining an alias.

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...
4
use League\Fractal\Resource\ResourceInterface;
5
6
class ScopeFactory extends \League\Fractal\ScopeFactory
7
{
8
    /**
9
     * @param \Pz\Doctrine\Rest\Fractal\Manager|Manager $manager
10
     * @param ResourceInterface                         $resource
11
     * @param null                                      $scopeIdentifier
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $scopeIdentifier is correct as it would always require null to be passed?
Loading history...
12
     *
13
     * @return Scope
14
     */
15 19
    public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null)
16
    {
17 19
        $scope = new Scope($manager, $resource, $scopeIdentifier);
18 19
        $scope->isRelationships($manager->request()->isRelationships());
0 ignored issues
show
introduced by
The method request() does not exist on League\Fractal\Manager. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $scope->isRelationships($manager->/** @scrutinizer ignore-call */ request()->isRelationships());
Loading history...
19
20 19
        return $scope;
21
    }
22
}
23