Completed
Pull Request — 2.x (#137)
by Akihito
06:23
created

Code::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Aop;
6
7
use Ray\Aop\Exception\NotWritableException;
8
9
final class Code
10
{
11
    /**
12
     * @var string
13
     */
14
    public $code = '';
15
16
s    public function save(string $classDir, string $aopClassName) : string
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
17
    {
18
        class_exists($aopClassName);
19
        $flatName = str_replace('\\', '_', $aopClassName);
20
        $filename = sprintf('%s/%s.php', $classDir, $flatName);
21
        $tmpFile = tempnam(dirname($filename), 'swap');
22
        if (is_string($tmpFile) && file_put_contents($tmpFile, $this->code) && rename($tmpFile, $filename)) {
23
            return $filename;
24
        }
25
        @unlink((string) $tmpFile);
26
27
        throw new NotWritableException(sprintf('swap: %s, file: %s', $tmpFile, $filename));
28
    }
29
}
30