Completed
Push — master ( c1625e...d10bcc )
by Hong
06:18
created

ExtraClauseTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 28 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 7 7 1
A after() 7 7 1
A buildBeforeAfter() 0 14 2
getClause() 0 1 ?

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
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Query
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Query\Traits\Clause;
16
17
use Phossa2\Query\Interfaces\Clause\ExtraClauseInterface;
18
19
/**
20
 * ExtraClauseTrait
21
 *
22
 * @package Phossa2\Query
23
 * @author  Hong Zhang <[email protected]>
24
 * @see     ExtraClauseInterface
25
 * @version 2.0.0
26
 * @since   2.0.0 added
27
 */
28
trait ExtraClauseTrait
29
{
30
    /**
31
     * {@inheritDoc}
32
     */
33 View Code Duplication
    public function before(/*# string */ $position, /*# string */ $rawString)
1 ignored issue
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...
34
    {
35
        $clause = &$this->getClause('BEFORE');
36
        $pos = strtoupper($position);
37
        $clause[$pos][] = $rawString;
38
        return $this;
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 View Code Duplication
    public function after(/*# string */ $position, /*# string */ $rawString)
1 ignored issue
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...
45
    {
46
        $clause = &$this->getClause('AFTER');
47
        $pos = strtoupper($position);
48
        $clause[$pos][] = $rawString;
49
        return $this;
50
    }
51
52
    /**
53
     * Build AFTER/BEFORE
54
     *
55
     * @param  string $beforeOrAfter BEFORE|AFTER
56
     * @param  string $position
57
     * @param  array $settings
58
     * @return string
59
     * @access protected
60
     */
61
    protected function buildBeforeAfter(
62
        /*# string */ $beforeOrAfter,
63
        /*# string */ $position,
64
        array $settings
65
    )/*# : string */ {
66
        $clause = &$this->getClause($beforeOrAfter);
67
        if (isset($clause[$position])) {
68
            $line = $clause[$position];
69
            $sepr = $settings['seperator'];
70
            return $sepr . join($sepr, $line);
71
        } else {
72
            return '';
73
        }
74
    }
75
76
    abstract protected function &getClause(/*# string */ $clauseName)/*# : array */;
77
}
78