Completed
Push — master ( 8c67c8...0fdee2 )
by Freek
01:59
created

StringTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canTransform() 0 4 1
A transform() 0 4 1
A escape() 0 4 1
1
<?php
2
3
namespace Spatie\BladeJavaScript\Transformers;
4
5
class StringTransformer  implements Transformer
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before implements keyword; 2 found
Loading history...
6
{
7
    public function canTransform($value): bool
8
    {
9
        return is_string($value);
10
    }
11
12
    /**
13
     * @param $value
14
     *
15
     * @return string
16
     */
17
    public function transform($value): string
18
    {
19
        return "'{$this->escape($value)}'";
20
    }
21
22
    protected function escape(string $value): string
23
    {
24
        return str_replace(['\\', "'"], ['\\\\', "\'"], $value);
25
    }
26
}
27