Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
10 / 10
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractFile
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
10 / 10
10
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 setGenerator
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getGenerator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 write
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFileName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFileExtension
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 writeFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFileDestination
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFile
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\File;
6
7use WsdlToPhp\PackageGenerator\Generator\Generator;
8use WsdlToPhp\PhpGenerator\Component\PhpFile;
9
10abstract class AbstractFile implements FileInterface
11{
12    public const PHP_FILE_EXTENSION = 'php';
13
14    protected Generator $generator;
15
16    protected PhpFile $file;
17
18    public function __construct(Generator $generator, string $name)
19    {
20        $this
21            ->setFile(new PhpFile($name))
22            ->setGenerator($generator)
23        ;
24    }
25
26    public function setGenerator(Generator $generator): self
27    {
28        $this->generator = $generator;
29
30        return $this;
31    }
32
33    public function getGenerator(): Generator
34    {
35        return $this->generator;
36    }
37
38    public function write(): void
39    {
40        $this->writeFile();
41    }
42
43    public function getFileName(): string
44    {
45        return sprintf('%s%s.%s', $this->getFileDestination(), $this->getFile()->getMainElement()->getName(), $this->getFileExtension());
46    }
47
48    public function getFileExtension(): string
49    {
50        return self::PHP_FILE_EXTENSION;
51    }
52
53    public function getFile(): PhpFile
54    {
55        return $this->file;
56    }
57
58    protected function writeFile(): void
59    {
60        file_put_contents($this->getFileName(), $this->getFile()->toString(), LOCK_EX);
61    }
62
63    protected function getFileDestination(): string
64    {
65        return $this->getGenerator()->getOptionDestination();
66    }
67
68    protected function setFile(PhpFile $file): self
69    {
70        $this->file = $file;
71
72        return $this;
73    }
74}