EntityService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkRepository() 0 6 2
A parseResult() 0 4 1
B dispatch() 0 22 5
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Service;
12
13
use InvalidArgumentException;
14
use Longman\Platfourm\Contracts\Repository\Repository;
15
16
abstract class EntityService
17
{
18
19
    protected function checkRepository()
20
    {
21
        if (!($this->repository instanceof Repository)) {
0 ignored issues
show
Bug introduced by
The property repository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
            throw new RepositoryNotFoundException;
23
        }
24
    }
25
26
    protected function parseResult($result)
27
    {
28
        return $result;
29
    }
30
31
    /**
32
     * @param  array $input
33
     * @throws InvalidValueException
34
     * @return mixed
35
     */
36
    public function dispatch(array $input, $methodName = 'run')
37
    {
38
        $method = new ReflectionMethod($this, $methodName);
39
        $params = $method->getParameters();
40
        //var_dump($params);
41
        $args = [];
42
        if (!empty($params)) {
43
            foreach ($params as $item) {
44
                if (!isset($input[$item->getName()])) {
45
                    if ($item->isDefaultValueAvailable()) {
46
                        $input[$item->getName()] = $item->getDefaultValue();
47
                    } else {
48
                        throw new InvalidArgumentException("field not found " . $item->getName());
49
                    }
50
                }
51
52
                $args[] = $input[$item->getName()];
53
            }
54
        }
55
56
        return call_user_func_array([$this, $methodName], $args);
57
    }
58
}
59