Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit b7e85cc

Browse files
committed
Exceptions refactoring
1 parent ca1374e commit b7e85cc

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/Checker.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace JakubBoucek\ComposerConsistency;
55

6-
use RuntimeException;
6+
use LogicException;
77

88
/**
99
* Class Checker
@@ -43,7 +43,7 @@ public function __construct(string $rootDir, ?string $vendorDir = null)
4343
* If `/vendor` is not comply requirements, checker throws an Exception
4444
* @param string $rootDir
4545
* @param string|null $vendorDir
46-
* @throws RuntimeException
46+
* @throws ComposerInconsitencyException
4747
*/
4848
public static function validateReqs(string $rootDir, ?string $vendorDir = null): void
4949
{
@@ -54,12 +54,12 @@ public static function validateReqs(string $rootDir, ?string $vendorDir = null):
5454
/**
5555
* Check validity of required packages in vendor
5656
* If `/vendor` is not comply requirements, checker throws an Exception
57-
* @throws RuntimeException
57+
* @throws ComposerInconsitencyException
5858
*/
5959
public function validate(): void
6060
{
6161
if ($this->isReqsValid() === false) {
62-
throw new RuntimeException(
62+
throw new ComposerInconsitencyException(
6363
'Composer has no consitent vendor directory with project requirements, call `composer install`'
6464
);
6565
}
@@ -69,7 +69,7 @@ public function validate(): void
6969
/**
7070
* If vendor is not comply requirements, checker return `false`
7171
* @return bool
72-
* @throws RuntimeException
72+
* @throws LogicException
7373
*/
7474
public function isReqsValid(): bool
7575
{
@@ -111,8 +111,7 @@ public function setStrictReqs(bool $strictReqs): self
111111

112112
/**
113113
* @return array
114-
* @throws FileReadException
115-
* @throws RuntimeException
114+
* @throws LogicException
116115
*/
117116
protected function loadReqs(): array
118117
{
@@ -130,8 +129,7 @@ protected function loadReqs(): array
130129

131130
/**
132131
* @return array
133-
* @throws FileReadException
134-
* @throws RuntimeException
132+
* @throws LogicException
135133
*/
136134
protected function loadReqsFile(): array
137135
{
@@ -141,8 +139,7 @@ protected function loadReqsFile(): array
141139

142140
/**
143141
* @return array
144-
* @throws FileReadException
145-
* @throws RuntimeException
142+
* @throws LogicException
146143
*/
147144
protected function loadInstalled(): array
148145
{
@@ -160,8 +157,7 @@ protected function loadInstalled(): array
160157

161158
/**
162159
* @return array
163-
* @throws FileReadException
164-
* @throws RuntimeException
160+
* @throws LogicException
165161
*/
166162
protected function loadInstalledFile(): array
167163
{
@@ -172,8 +168,7 @@ protected function loadInstalledFile(): array
172168
/**
173169
* @param string $filename
174170
* @return array
175-
* @throws FileReadException
176-
* @throws RuntimeException
171+
* @throws LogicException
177172
*/
178173
protected function readJsonFile(string $filename): array
179174
{
@@ -203,15 +198,15 @@ protected function readFile(string $file): string
203198
/**
204199
* @param string $json
205200
* @return array
206-
* @throws RuntimeException
201+
* @throws LogicException
207202
* @link https://doc.nette.org/en/3.0/json
208203
*/
209204
protected function parseJsonArray(string $json): array
210205
{
211206
$value = json_decode($json, true, 512, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR);
212207
if (is_array($value) === false) {
213208
$type = gettype($value);
214-
throw new RuntimeException("Expected Json-serialized Array, but $type instead.");
209+
throw new LogicException("Expected Json-serialized Array, but $type instead.");
215210
}
216211
return $value;
217212
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace JakubBoucek\ComposerConsistency;
6+
7+
use LogicException;
8+
9+
class ComposerInconsitencyException extends LogicException
10+
{
11+
12+
}

src/FileReadException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
namespace JakubBoucek\ComposerConsistency;
55

6-
use RuntimeException;
6+
use LogicException;
77
use Throwable;
88

9-
class FileReadException extends RuntimeException
9+
class FileReadException extends LogicException
1010
{
1111
/**
1212
* @var string

0 commit comments

Comments
 (0)