Skip to content

Commit 415cd2e

Browse files
committed
Updated tests, CI, coding standard and added some minor fixes based on Psalm analysis.
1 parent 97e6e02 commit 415cd2e

File tree

8 files changed

+51
-35
lines changed

8 files changed

+51
-35
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
language: php
22

33
php:
4-
- 7.1
5-
- 7.2
64
- 7.3
75
- 7.4
6+
- nightly
87

98
notifications:
109
email:
1110
1211

13-
before_script: composer install
12+
before_script: composer install --ignore-platform-reqs
1413

1514
script:
1615
- vendor/bin/phpunit --configuration phpunit.xml < tests/input.txt
16+
- vendor/bin/psalm --show-info=true

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Utopia CLI
22

3-
[![Build Status](https://travis-ci.org/utopia-php/cli.svg?branch=master)](https://travis-ci.org/utopia-php/cli)
3+
[![Build Status](https://travis-ci.org/utopia-php/cli.svg?branch=master)](https://travis-ci.com/utopia-php/cli)
44
![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/cli.svg)
5-
[![Discord](https://badgen.net/badge/discord/chat/green)](https://discord.gg/GSeTUeA)
5+
[![Discord](https://badgen.net/badge/discord/chat/green)](https://appwrite.io/discord)
66

7-
Utopia framework CLI library is simple and lite library for extending Utopia PHP Framework to be able to code command line applications. This library is aiming to be as simple and easy to learn and use.
7+
Utopia framework CLI library is simple and lite library for extending Utopia PHP Framework to be able to code command line applications. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).
88

99
Although this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free and can be used as standalone with any other PHP project or framework.
1010

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"utopia-php/framework": "0.*.*"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^7.0"
21+
"phpunit/phpunit": "^9.3",
22+
"vimeo/psalm": "4.0.1"
2223
},
2324
"minimum-stability": "dev"
2425
}

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="7"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/CLI/CLI.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CLI {
3939
*
4040
* An error callback
4141
*
42-
* @var callback
42+
* @var callable
4343
*/
4444
protected $error = null;
4545

@@ -48,18 +48,18 @@ class CLI {
4848
*
4949
* A callback function that is initialized on application start
5050
*
51-
* @var callback[]
51+
* @var callable[]
5252
*/
53-
protected $init = array();
53+
protected $init = [];
5454

5555
/**
5656
* Shutdown
5757
*
5858
* A callback function that is initialized on application end
5959
*
60-
* @var callback[]
60+
* @var callable[]
6161
*/
62-
protected $shutdown = array();
62+
protected $shutdown = [];
6363

6464
/**
6565
* CLI constructor.
@@ -175,7 +175,7 @@ public function run()
175175
try {
176176
if($command) {
177177
foreach($this->init as $init) {
178-
\call_user_func_array($init, array());
178+
\call_user_func_array($init, []);
179179
}
180180

181181
$params = [];
@@ -193,7 +193,7 @@ public function run()
193193
\call_user_func_array($command->getAction(), $params);
194194

195195
foreach($this->shutdown as $shutdown) {
196-
\call_user_func_array($shutdown, array());
196+
\call_user_func_array($shutdown, []);
197197
}
198198
}
199199
else {

src/CLI/Console.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ static public function execute(string $cmd, string $stdin = null, string &$stdou
137137
$stderr = '';
138138

139139
if (\is_resource($process)) {
140-
\stream_set_blocking($pipes[0], 0);
141-
\stream_set_blocking($pipes[1], 0);
142-
\stream_set_blocking($pipes[2], 0);
140+
\stream_set_blocking($pipes[0], false);
141+
\stream_set_blocking($pipes[1], false);
142+
\stream_set_blocking($pipes[2], false);
143143

144144
\fwrite($pipes[0], $stdin);
145145
\fclose($pipes[0]);

src/CLI/Task.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Task
1919
/**
2020
* Action Callback
2121
*
22-
* @var null|callback
22+
* @var callable
2323
*/
24-
protected $action = null;
24+
protected $action;
2525

2626
/**
2727
* Parameters
@@ -30,7 +30,7 @@ class Task
3030
*
3131
* @var array
3232
*/
33-
protected $params = array();
33+
protected $params = [];
3434

3535
/**
3636
* Labels
@@ -39,13 +39,13 @@ class Task
3939
*
4040
* @var array
4141
*/
42-
protected $labels = array();
42+
protected $labels = [];
4343

4444
/**
4545
* Task constructor.
46-
* @param $name
46+
* @param string $name
4747
*/
48-
public function __construct($name)
48+
public function __construct(string $name)
4949
{
5050
$this->name = $name;
5151
}
@@ -56,7 +56,7 @@ public function __construct($name)
5656
* @param string $desc
5757
* @return $this
5858
*/
59-
public function desc($desc)
59+
public function desc($desc): self
6060
{
6161
$this->desc = $desc;
6262
return $this;
@@ -65,10 +65,10 @@ public function desc($desc)
6565
/**
6666
* Add Action
6767
*
68-
* @param $action
68+
* @param callable $action
6969
* @return $this
7070
*/
71-
public function action($action)
71+
public function action(callable $action): self
7272
{
7373
$this->action = $action;
7474
return $this;
@@ -78,14 +78,14 @@ public function action($action)
7878
* Add Param
7979
*
8080
* @param string $key
81-
* @param null $default
81+
* @param mixed $default
8282
* @param string $validator
8383
* @param string $description
8484
* @param bool $optional
8585
*
8686
* @return $this
8787
*/
88-
public function param($key, $default, $validator, $description = '', $optional = false)
88+
public function param(string $key, $default, $validator, string $description = '', bool $optional = false): self
8989
{
9090
$this->params[$key] = array(
9191
'default' => $default,
@@ -106,7 +106,7 @@ public function param($key, $default, $validator, $description = '', $optional =
106106
*
107107
* @return $this
108108
*/
109-
public function label($key, $value)
109+
public function label(string $key, $value): self
110110
{
111111
$this->labels[$key] = $value;
112112

@@ -118,17 +118,17 @@ public function label($key, $value)
118118
*
119119
* @return string
120120
*/
121-
public function getDesc()
121+
public function getDesc(): string
122122
{
123123
return $this->desc;
124124
}
125125

126126
/**
127127
* Get Action
128128
*
129-
* @return callable|null
129+
* @return callable
130130
*/
131-
public function getAction()
131+
public function getAction(): callable
132132
{
133133
return $this->action;
134134
}
@@ -138,7 +138,7 @@ public function getAction()
138138
*
139139
* @return array
140140
*/
141-
public function getParams()
141+
public function getParams(): array
142142
{
143143
return $this->params;
144144
}
@@ -152,7 +152,7 @@ public function getParams()
152152
* @param mixed $default
153153
* @return mixed
154154
*/
155-
public function getLabel($key, $default)
155+
public function getLabel(string $key, $default)
156156
{
157157
return (isset($this->labels[$key])) ? $this->labels[$key] : $default;
158158
}

tests/CLI/CLITest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testAppFailure()
6969
$this->assertEquals('', $result);
7070
}
7171

72-
public function testAppArray()
72+
public function testApp[]
7373
{
7474
ob_start();
7575

0 commit comments

Comments
 (0)