Skip to content

Commit

Permalink
Merge pull request #14 from phar-io/feature/custom-exceptions
Browse files Browse the repository at this point in the history
Add custom exception
  • Loading branch information
sebastianfeldmann authored Nov 25, 2020
2 parents 05dca07 + f5bc5d8 commit 3862ed4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace PharIo\ComposerDistributor\Config;

use PharIo\ComposerDistributor\FileList;
use RuntimeException;

class Config
{
Expand All @@ -21,7 +20,7 @@ class Config
public function __construct(string $package, FileList $phars, ?string $keyDir = null)
{
if (strpos($package, '/') === false) {
throw new RuntimeException('Invalid package name');
throw InvalidPackageName::fromString($package);
}
$this->package = $package;
$this->phars = $phars;
Expand Down
15 changes: 15 additions & 0 deletions src/Config/InvalidPackageName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace PharIo\ComposerDistributor\Config;

use RuntimeException;

final class InvalidPackageName extends RuntimeException
{
public static function fromString(string $name): InvalidPackageName
{
return new self(sprintf('Invalid package name: %s', $name));
}
}
1 change: 0 additions & 1 deletion src/Config/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace PharIo\ComposerDistributor\Config;

use DOMDocument;
use RuntimeException;

class Loader
{
Expand Down
1 change: 0 additions & 1 deletion tests/unit/Config/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PharIo\ComposerDistributor\Config\FileNotFound;
use PharIo\ComposerDistributor\Config\InvalidXML;
use PharIo\ComposerDistributor\Config\ValidationFailed;
use PharIo\ComposerDistributor\Config\Loader;
use PHPUnit\Framework\TestCase;

Expand Down

0 comments on commit 3862ed4

Please sign in to comment.