FormulaHydrator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 4 1
A __construct() 0 6 1
A hydrate() 0 4 1
A createEmptyInstance() 0 5 1
1
<?php
2
/**
3
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\formula;
12
13
use hiqdev\php\billing\formula\FormulaEngine;
14
use hiqdev\php\billing\formula\FormulaEngineInterface;
15
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator;
16
use Zend\Hydrator\HydratorInterface;
17
18
/**
19
 * Formula Hydrator.
20
 *
21
 * @author Andrii Vasyliev <[email protected]>
22
 */
23
class FormulaHydrator extends GeneratedHydrator
24
{
25
    /**
26
     * @var FormulaEngineInterface|FormulaEngine
27
     */
28
    protected $formulaEngine;
29
30
    public function __construct(
31
        HydratorInterface $hydrator,
32
        FormulaEngineInterface $formulaEngine
33
    ) {
34
        parent::__construct($hydrator);
35
        $this->formulaEngine = $formulaEngine;
36
    }
37
38
    public function hydrate(array $data, $object)
39
    {
40
        /// XXX actual data setting in createEmptyInstance
41
        return $object;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     * @param object|Money $object
0 ignored issues
show
Bug introduced by
The type hiqdev\billing\hiapi\formula\Money was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
     */
48
    public function extract($object)
49
    {
50
        return array_filter([
51
            'text'  => (string) $object,
52
        ]);
53
    }
54
55
    /**
56
     * @param string $className
57
     * @param array $data
58
     * @throws \ReflectionException
59
     * @return object
60
     */
61
    public function createEmptyInstance(string $className, array $data = [])
0 ignored issues
show
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

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

61
    public function createEmptyInstance(/** @scrutinizer ignore-unused */ string $className, array $data = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
        $formula = $data['formula'] ?? reset($data);
64
65
        return $this->formulaEngine->build($formula);
66
    }
67
}
68