• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 11800557345

12 Nov 2024 03:33PM UTC coverage: 82.436% (-0.02%) from 82.455%
11800557345

Pull #647

github

web-flow
Merge b39c42cf3 into d599d5047
Pull Request #647: feat(console): add `make:controller` and `make:model` commands

175 of 213 new or added lines in 12 files covered. (82.16%)

19 existing lines in 2 files now uncovered.

7425 of 9007 relevant lines covered (82.44%)

51.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.25
/src/Tempest/Generation/src/ClassManipulator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Generation;
6

7
use Nette\PhpGenerator\ClassType;
8
use Nette\PhpGenerator\PhpFile;
9
use ReflectionClass;
10
use Tempest\Generation\Exceptions\FileGenerationFailedException;
11

12
final class ClassManipulator
13
{
14
    use ManipulatesPhpClasses;
15

16
    public function __construct(string|ReflectionClass $source)
25✔
17
    {
18
        if (is_file($source)) {
25✔
19
            /** @phpstan-ignore-next-line */
20
            $this->classType = ClassType::fromCode(file_get_contents($source));
4✔
21
        } elseif (is_string($source)) {
21✔
22
            /** @phpstan-ignore-next-line */
23
            $this->classType = ClassType::from($source, withBodies: true);
21✔
24
        } else {
25
            /** @phpstan-ignore-next-line */
26
            $this->classType = ClassType::from($source->getName(), withBodies: true);
×
27
        }
28

29
        $this->file = new PhpFile();
24✔
30
        $this->namespace = $this->classType->getNamespace()->getName();
24✔
31
    }
32

33
    /**
34
     * Save the class to a target file.
35
     *
36
     * @param string $path the path to save the class to.
37
     *
38
     * @throws FileGenerationFailedException if the file could not be written.
39
     */
40
    public function save(string $path): self
8✔
41
    {
42
        $dir = pathinfo($path, PATHINFO_DIRNAME);
8✔
43

44
        if (! is_dir($dir)) {
8✔
45
            mkdir($dir, recursive: true);
×
46
        }
47

48
        $isSuccess = (bool) file_put_contents($path, $this->print());
8✔
49

50
        if (! $isSuccess) {
8✔
NEW
51
            throw new FileGenerationFailedException(sprintf('The file "%s" could not be written.', $path));
×
52
        }
53

54
        return $this;
8✔
55
    }
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc