edmondscommerce/doctrine-static-meta

View on GitHub
src/CodeGeneration/Filesystem/Directory.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem;

use RuntimeException;

class Directory extends AbstractFilesystemItem
{
    /**
     * This is the name of the path type. It should be overriden in child classes.
     *
     * @var string
     */
    protected const PATH_TYPE = 'directory';

    protected function doCreate(): void
    {
        if (!mkdir($this->path, $this->createModeOctal, true) && !is_dir($this->path)) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException(sprintf('Directory "%s" was not created', $this->path));
            // @codeCoverageIgnoreEnd
        }
    }

    protected function isCorrectType(): bool
    {
        return $this->createSplFileInfo()->isDir();
    }
}