Completed
Push — master ( f0e6de...68f317 )
by Hong
03:39
created

ExtraTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 29.17 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 7 7 1
A after() 7 7 1
A buildBeforeAfter() 0 14 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
 * 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\ExtraInterface;
18
19
/**
20
 * ExtraTrait
21
 *
22
 * @package Phossa2\Query
23
 * @author  Hong Zhang <[email protected]>
24
 * @see     ExtraInterface
25
 * @version 2.0.0
26
 * @since   2.0.0 added
27
 */
28
trait ExtraTrait
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');
0 ignored issues
show
Bug introduced by
It seems like getClause() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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');
0 ignored issues
show
Bug introduced by
It seems like getClause() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like getClause() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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