LazyLoaderTrait::loadDelegates()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 36
Code Lines 19

Duplication

Lines 10
Ratio 27.78 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 10
loc 36
ccs 0
cts 29
cp 0
rs 8.439
c 0
b 0
f 0
cc 5
eloc 19
nc 6
nop 1
crap 30
1
<?php
2
3
namespace Majora\Framework\Loader;
4
5
use Majora\Framework\Model\LazyPropertiesInterface;
6
7
/**
8
 * Implements entity lazy loading delegates hydration.
9
 */
10
trait LazyLoaderTrait
11
{
12
    /**
13
     * Hydrate lazy loads delegate into given Collectionnable, if enabled and if
14
     * entity supports it.
15
     *
16
     * @param LazyPropertiesInterface $object (not hinted to help notation and custom exception)
0 ignored issues
show
Bug introduced by
There is no parameter named $object. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
17
     *
18
     * @return LazyPropertiesInterface
19
     */
20
    private function loadDelegates($entity)
21
    {
22
        if (!$this instanceof LazyLoaderInterface) {
23
            return $entity;
24
        }
25
        if (!$entity instanceof LazyPropertiesInterface) {
26
            throw new \InvalidArgumentException(sprintf('%s objects cannot be hydrated with properties loading delegates without implementing %s.',
27
                get_class($entity),
28
                LazyPropertiesInterface::class
29
            ));
30
        }
31
32
        // global handler (deprecated)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33 View Code Duplication
        if (isset($proxies[$loaderClass = static::class])) {
0 ignored issues
show
Bug introduced by
The variable $proxies seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
35
                sprintf('Global loader delegate is deprecated and will be removed in 1.6. Make "%s" loader invokable instead, entity to handle is given at first parameter.',
36
                    static::class
37
                ),
38
                E_USER_DEPRECATED
39
            );
40
            $proxies[$loaderClass]($entity);
41
            unset($proxies[$loaderClass]);
42
        }
43
44
        // define delegates into object
45
        $entity->registerLoaders(
46
            $this->getLoadingDelegates()
47
        );
48
49
        // global handler
50
        if (is_callable($this)) {
51
            $this($entity);
52
        }
53
54
        return $entity;
55
    }
56
}
57