<?php
declare(strict_types=1);

namespace RoundingWell\Schematic;

/**
 * @codeCoverageIgnore
 */
class System
{
    public function writeFile(string $file, string $contents): int
    {
        return (int) file_put_contents($file, $contents);
    }
}

<?php
declare(strict_types=1);

namespace RoundingWell\Schematic;

/**
 * @codeCoverageIgnore
 */
class System
{
    public function writeFile(string $file, string $contents): int
    {
        $directory = pathinfo($file, PATHINFO_DIRNAME);

        if (!file_exists($directory)) {
            mkdir($directory, 0755, true);
        }

        return (int) file_put_contents($file, $contents);
    }
}

Create missing directories when writing files
Create missing directories when writing files

Ensure that the directory exists before writing to it.
