Completed
Pull Request — master (#8)
by Саша
21:35
created

BaseContext::createDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
use Behat\Behat\Context\Context;
4
use Behat\Gherkin\Node\PyStringNode;
5
6
class BaseContext implements Context
7
{
8
    protected static $workingDirectory;
9
10
    protected function createFile($name, $content)
11
    {
12
        $path = self::$workingDirectory.$name;
13
14
        $this->createDirectory(dirname($path));
15
16
        file_put_contents($path, $content);
17
18
        return $path;
19
    }
20
21
    protected function createFileFromStringNode($name, PyStringNode $content)
22
    {
23
        return $this->createFile(
24
            $name,
25
            $this->stringNodeToString($content)
26
        );
27
    }
28
29
    protected function createDirectory($path)
30
    {
31
        if (!is_dir($path)) {
32
            mkdir($path, 0777, true);
33
        }
34
    }
35
36
    protected function stringNodeToString(PyStringNode $string)
37
    {
38
        return strtr((string) $string, array("'''" => '"""'));
39
    }
40
}
41