protected function writeDeclaration(ClassDeclaration $declaration, string $type = null)
    {
        $type = $type ?? static::ELEMENT;

        $filename = $this->config->classFilename($type, $this->argument('name'));
        $filename = $this->files->normalizePath($filename);

        if ($this->files->exists($filename)) {
            $this->writeln(
                "<fg=red>Unable to create '<comment>{$declaration->getName()}</comment>' declaration, "
                . "file '<comment>{$filename}</comment>' already exists.</fg=red>"
            );

            return;
        }

        //File declaration
        $file = new FileDeclaration(
            $this->config->classNamespace($type, $this->argument('name'))
        );

        $file->setComment($this->config->headerLines());
        $file->addElement($declaration);

        $this->files->write(
            $filename,
            $file->render(),
            FilesInterface::READONLY,
            true
        );

        $this->writeln(
            "Declaration of '<info>{$declaration->getName()}</info>' "
            . "has been successfully written into '<comment>{$filename}</comment>'."
        );
    }