-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRequest.php
More file actions
81 lines (70 loc) · 2.06 KB
/
Copy pathRequest.php
File metadata and controls
81 lines (70 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/
namespace PHPCSDevTools\Scripts\Scaffold\Console;
use PHPCSDevTools\Tests\Scaffold\RequestTest;
/**
* Represents the validated inputs needed to run the scaffold application.
*
* @see RequestTest
*/
final class Request implements RequestInterface
{
/**
* The command line arguments.
*
* @var list<non-empty-string>
*/
private $arguments;
/**
* Create a new application arguments value object.
*
* @param list<string> $arguments the command line arguments passed to the application
*
* @throws \InvalidArgumentException if any argument is not a non-empty string
*/
public function __construct(array $arguments)
{
foreach ($arguments as $argument) {
if (\is_string($argument) === false) {
throw new \InvalidArgumentException(\sprintf(
'Each argument must be a string. "%s" given.',
\is_object($argument) ? \get_class($argument) : \gettype($argument)
));
}
if (\trim($argument) === '') {
throw new \InvalidArgumentException('Each argument must be a non-empty-string.');
}
}
$this->arguments = $arguments;
}
/**
* Get the command.
*
* @throws \InvalidArgumentException if no arguments are provided
*
* @return non-empty-string
*/
public function getCommand()
{
foreach ($this->arguments as $argument) {
return $argument;
}
throw new \InvalidArgumentException('At least one argument is required to determine the command.');
}
/**
* Get command line arguments as an array.
*
* @return list<non-empty-string>
*/
public function toArray()
{
return $this->arguments;
}
}