Bitwise   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 20.59 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 14
loc 68
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 2
A transform() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Happyr\DoctrineSpecification\Operand;
15
16
use Doctrine\ORM\QueryBuilder;
17
use Happyr\DoctrineSpecification\Exception\InvalidArgumentException;
18
19
@trigger_error('The '.__NAMESPACE__.'\Bitwise class is deprecated since version 1.1 and will be removed in 2.0.', E_USER_DEPRECATED);
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...
20
21
/**
22
 * @deprecated This class is deprecated since version 1.1 and will be removed in 2.0.
23
 */
24
abstract class Bitwise implements Operand
25
{
26
    const B_AND = '&';
27
28
    const B_OR = '|';
29
30
    const B_XOR = '^';
31
32
    const B_LS = '<<';
33
34
    const B_RS = '>>';
35
36
    /**
37
     * @var string[]
38
     */
39
    private static $operations = [
40
        self::B_AND,
41
        self::B_OR,
42
    ];
43
44
    /**
45
     * @var string
46
     */
47
    private $operation;
48
49
    /**
50
     * @var Operand|string
51
     */
52
    private $field;
53
54
    /**
55
     * @var Operand|string
56
     */
57
    private $value;
58
59
    /**
60
     * @param string         $operation
61
     * @param Operand|string $field
62
     * @param Operand|string $value
63
     */
64 View Code Duplication
    public function __construct($operation, $field, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
65
    {
66
        if (!in_array($operation, self::$operations, true)) {
67
            throw new InvalidArgumentException(sprintf(
68
                '"%s" is not a valid bitwise operation. Valid operations are: "%s"',
69
                $operation,
70
                implode(', ', self::$operations)
71
            ));
72
        }
73
74
        $this->operation = $operation;
75
        $this->field = $field;
76
        $this->value = $value;
77
    }
78
79
    /**
80
     * @param QueryBuilder $qb
81
     * @param string       $dqlAlias
82
     *
83
     * @return string
84
     */
85
    public function transform(QueryBuilder $qb, $dqlAlias)
86
    {
87
        $function = self::B_AND === $this->operation ? 'BIT_AND' : 'BIT_OR';
88
89
        return (new PlatformFunction($function, $this->field, $this->value))->transform($qb, $dqlAlias);
90
    }
91
}
92