StringType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A formatLiteralString() 0 10 1
1
<?php
2
namespace Desmond\data_types;
3
4
class StringType extends AbstractAtom
5
{
6 363
    public function __construct($token, $dontFormat=false)
7
    {
8 363
        if ($dontFormat) {
9 9
            $this->setValue($token);
10 9
            return;
11
        }
12 363
        $this->setValue($this->formatLiteralString($token));
13 363
    }
14
15 363
    private function formatLiteralString($string)
16
    {
17
        $searches = [
18 363
            '/^"|"$/', // Opening and closing quotes.
19
            '/\\\"/', // Quotes preceeded by backslash (\")
20
            '/\\\n/' // New lines (\n)
21
        ];
22 363
        $replaces = ['', '"', "\n"];
23 363
        return preg_replace($searches, $replaces , $string);
24
    }
25
}
26