Skip to content

Commit

Permalink
Add Workspace.php
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Jul 17, 2024
1 parent 357de44 commit 9045ee7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Workspace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Ghostwriter\Arm;

use Ghostwriter\Arm\Interface\WorkspaceInterface;
use Ghostwriter\Arm\Service\Factory\WorkspaceFactory;
use Ghostwriter\Container\Attribute\Factory;
use InvalidArgumentException;
use Override;

use function is_dir;
use function trim;

#[Factory(WorkspaceFactory::class)]
final readonly class Workspace implements WorkspaceInterface
{
public function __construct(
private string $workspace
) {
if (trim($workspace) === '') {
throw new InvalidArgumentException('Workspace cannot be empty');
}

if (! is_dir($workspace)) {
throw new InvalidArgumentException('Workspace must be a directory');
}
}

#[Override]
public function toString(): string
{
return $this->workspace;
}

#[Override]
public static function new(string $workspace): self
{
return new self($workspace);
}
}

0 comments on commit 9045ee7

Please sign in to comment.