Literal::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Greppy package.
5
 *
6
 * (c) Daniel Ribeiro <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Relax\Greppy\Pattern\Element;
13
14
use Relax\Greppy\Pattern\ElementInterface;
15
16
/**
17
 * Class Literal
18
 *
19
 * @author Daniel Ribeiro <[email protected]>
20
 * @package Relax\Greppy\Pattern\Element
21
 */
22
class Literal implements ElementInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    private $literal;
28
29
    /**
30
     * @param $literal
31
     */
32
    public function __construct($literal)
33
    {
34
        $this->literal = $literal;
35
    }
36
    
37
    /**
38
     * Gets the string representation of the element for usage inside patterns.
39
     *
40
     * @return mixed
41
     */
42
    public function __toString()
43
    {
44
        if (ctype_alnum($this->literal)) {
45
            return $this->literal;
46
        }
47
        
48
        return sprintf("\%s", $this->literal);
49
    }
50
}
51