Completed
Push — master ( d10bcc...5ab9f6 )
by Hong
02:33
created

ExtraClauseTrait::beforeAfter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
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
    public function before(/*# string */ $position, /*# string */ $rawString)
34
    {
35
        return $this->beforeAfter('BEFORE', $position, $rawString);
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function after(/*# string */ $position, /*# string */ $rawString)
42
    {
43
        return $this->beforeAfter('AFTER', $position, $rawString);
44
    }
45
46
    /**
47
     * @param  string $type
48
     * @param  string $position
49
     * @param  string $rawString
50
     * @return $this
51
     * @access protected
52
     */
53
    protected function beforeAfter(
54
        /*# string */ $type,
55
        /*# string */ $position,
56
        /*# string */ $rawString
57
    ) {
58
        $clause = &$this->getClause($type);
59
        $pos = strtoupper($position);
60
        $clause[$pos][] = $rawString;
61
        return $this;
62
    }
63
64
    /**
65
     * Build AFTER/BEFORE
66
     *
67
     * @param  string $beforeOrAfter BEFORE|AFTER
68
     * @param  string $position
69
     * @param  array $settings
70
     * @return string
71
     * @access protected
72
     */
73
    protected function buildBeforeAfter(
74
        /*# string */ $beforeOrAfter,
75
        /*# string */ $position,
76
        array $settings
77
    )/*# : string */ {
78
        $clause = &$this->getClause($beforeOrAfter);
79
        if (isset($clause[$position])) {
80
            $line = $clause[$position];
81
            $sepr = $settings['seperator'];
82
            return $sepr . join($sepr, $line);
83
        } else {
84
            return '';
85
        }
86
    }
87
88
    abstract protected function &getClause(/*# string */ $clauseName)/*# : array */;
89
}
90