Skip to content

Commit e9f7056

Browse files
committed
breaking: migrate to php 8.0+ syntax
1 parent 594725f commit e9f7056

19 files changed

+183
-176
lines changed

.github/workflows/php.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
strategy:
1616
fail-fast: true
1717
matrix:
18-
php: [7.3, 7.4, 8.0] #
18+
php: [8.0, 8.1] # 7.3, 7.4,
1919
os: [ubuntu-latest, macOS-latest] # windows-latest,
20-
include:
21-
- os: 'ubuntu-latest'
22-
php: '7.2'
23-
phpunit: '8.5.13'
20+
# include:
21+
# - os: 'ubuntu-latest'
22+
# php: '7.2'
23+
# phpunit: '8.5.13'
2424

2525
steps:
2626
- name: Checkout

.github/workflows/release.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [7.4]
16+
php: [8.0]
1717

1818
steps:
1919
- name: Checkout
@@ -40,23 +40,23 @@ jobs:
4040
run: |
4141
tag1=${GITHUB_REF#refs/*/}
4242
echo "release tag: ${tag1}"
43-
composer install --no-progress --no-suggest
43+
composer install --no-progress
4444
45-
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
46-
# Docs: https://getcomposer.org/doc/articles/scripts.md
47-
48-
# - name: Build phar and send to github assets
49-
# run: |
50-
# echo $RELEASE_TAG
51-
# echo $RELEASE_NAME
52-
# php -d phar.readonly=0 bin/kite phar:pack -o kite-${RELEASE_TAG}.phar --no-progress
53-
# php kite-${RELEASE_TAG}.phar -V
45+
# more see https://github.com/inhere/kite
46+
- name: Generate changelog file
47+
id: changelog
48+
run: |
49+
wget -c -q https://github.com/inhere/kite/releases/latest/download/kite.phar
50+
php kite.phar git cl prev last --style gh-release --no-merges --fetch-tags --unshallow --file changelog.md
51+
cat changelog.md
5452
55-
# https://github.com/actions/create-release
56-
- uses: meeDamian/github-release@2.0
53+
# https://github.com/softprops/action-gh-release
54+
- name: Create release and upload assets
55+
uses: softprops/action-gh-release@v1
5756
with:
58-
gzip: false
59-
token: ${{ secrets.GITHUB_TOKEN }}
60-
tag: ${{ env.RELEASE_TAG }}
6157
name: ${{ env.RELEASE_TAG }}
62-
# files: kite-${{ env.RELEASE_TAG }}.phar
58+
tag_name: ${{ env.RELEASE_TAG }}
59+
body_path: changelog.md
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
# GITHUB_REPOSITORY: my_gh_org/my_gh_repo

example/property_exists.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Cmd/AbstractCmdBuilder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,51 @@ abstract class AbstractCmdBuilder
2525
/**
2626
* @var string
2727
*/
28-
protected $command = '';
28+
protected string $command = '';
2929

3030
/**
3131
* @var string
3232
*/
33-
protected $workDir;
33+
protected string $workDir;
3434

3535
/**
3636
* @var int
3737
*/
38-
protected $code = 0;
38+
protected int $code = 0;
3939

4040
/**
4141
* @var string
4242
*/
43-
protected $error = '';
43+
protected string $error = '';
4444

4545
/**
4646
* @var string
4747
*/
48-
protected $output = '';
48+
protected string $output = '';
4949

5050
/**
5151
* Dry run all commands
5252
*
5353
* @var bool
5454
*/
55-
protected $dryRun = false;
55+
protected bool $dryRun = false;
5656

5757
/**
5858
* @var bool
5959
*/
60-
protected $printCmd = true;
60+
protected bool $printCmd = true;
6161

6262
/**
6363
* Ignore check prevision return code
6464
*
6565
* @var bool
6666
*/
67-
protected $ignoreError = false;
67+
protected bool $ignoreError = false;
6868

6969
/**
7070
* @var bool
7171
*/
72-
protected $printOutput = false;
72+
protected bool $printOutput = false;
7373

7474
/**
7575
* Class constructor.

src/Cmd/CmdBuilder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class CmdBuilder extends AbstractCmdBuilder
2020
/**
2121
* @var string
2222
*/
23-
protected $bin = '';
23+
protected string $bin = '';
2424

2525
/**
2626
* @var array|string[]
2727
*/
28-
protected $args = [];
28+
protected array $args = [];
2929

3030
/**
3131
* @param string $bin
@@ -69,11 +69,11 @@ public function __construct(string $bin = '', string $workDir = '')
6969
}
7070

7171
/**
72-
* @param string|int $arg
72+
* @param int|string $arg
7373
*
7474
* @return $this
7575
*/
76-
public function add($arg): self
76+
public function add(int|string $arg): self
7777
{
7878
$this->args[] = $arg;
7979
return $this;
@@ -92,12 +92,12 @@ public function addf(string $format, ...$a): self
9292
}
9393

9494
/**
95-
* @param string|int $arg
95+
* @param int|string $arg
9696
* @param bool|int|string $ifExpr
9797
*
9898
* @return $this
9999
*/
100-
public function addIf($arg, $ifExpr): self
100+
public function addIf(int|string $arg, bool|int|string $ifExpr): self
101101
{
102102
if ($ifExpr) {
103103
$this->args[] = $arg;
@@ -107,11 +107,11 @@ public function addIf($arg, $ifExpr): self
107107
}
108108

109109
/**
110-
* @param string|int $arg
110+
* @param int|string $arg
111111
*
112112
* @return $this
113113
*/
114-
public function addArg($arg): self
114+
public function addArg(int|string $arg): self
115115
{
116116
$this->args[] = $arg;
117117
return $this;

src/Exec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static function run(string $command, string $cwd = ''): array
156156
*
157157
* @return array|string
158158
*/
159-
public static function auto(string $command, bool $returnStatus = true, string $cwd = '')
159+
public static function auto(string $command, bool $returnStatus = true, string $cwd = ''): array|string
160160
{
161161
$status = 1;
162162
$curDir = '';
@@ -207,7 +207,7 @@ public static function auto(string $command, bool $returnStatus = true, string $
207207
* @return mixed
208208
* @throws RuntimeException
209209
*/
210-
public static function execWithSudo(string $command, string $logfile = '', string $user = '')
210+
public static function execWithSudo(string $command, string $logfile = '', string $user = ''): mixed
211211
{
212212
// If should run as another user, we must be on *nix and must have sudo privileges.
213213
$suDo = '';

src/Proc/ProcFunc.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function open(
6060
*/
6161
public static function getStatus($process): array
6262
{
63-
return (array)proc_get_status($process);
63+
return proc_get_status($process);
6464
}
6565

6666
/**
@@ -80,12 +80,13 @@ public static function close($process): int
8080
* Kills a process opened by `proc_open`
8181
*
8282
* @param resource $process
83+
* @param int $signal
8384
*
8485
* @return bool
8586
* @see https://www.php.net/manual/en/function.proc-terminate.php
8687
*/
87-
public static function terminate($process): bool
88+
public static function terminate($process, int $signal = 15): bool
8889
{
89-
return proc_terminate($process);
90+
return proc_terminate($process, $signal);
9091
}
9192
}

src/Proc/ProcManager.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Toolkit\Sys\Proc;
4+
5+
use Toolkit\Stdlib\Helper\Assert;
6+
use Toolkit\Stdlib\Obj\Traits\AutoConfigTrait;
7+
8+
/**
9+
* class ProcManager
10+
*
11+
* @author inhere
12+
*/
13+
class ProcManager
14+
{
15+
use AutoConfigTrait;
16+
17+
/**
18+
* @var callable
19+
*/
20+
private $handler;
21+
22+
private int $procNum = 1;
23+
24+
/**
25+
* @var string custom process name
26+
*/
27+
private string $procName = '';
28+
29+
public function run(): self
30+
{
31+
Assert::notNull($this->handler, 'process: logic handler must be set before run');
32+
$handler = $this->handler;
33+
34+
35+
return $this;
36+
}
37+
38+
/**
39+
* @param callable $handler
40+
*
41+
* @return $this
42+
*/
43+
public function setHandler(callable $handler): self
44+
{
45+
$this->handler = $handler;
46+
return $this;
47+
}
48+
49+
/**
50+
* @return int
51+
*/
52+
public function getProcNum(): int
53+
{
54+
return $this->procNum;
55+
}
56+
57+
/**
58+
* @param int $procNum
59+
*
60+
* @return ProcManager
61+
*/
62+
public function setProcNum(int $procNum): self
63+
{
64+
Assert::intShouldGt0($procNum);
65+
$this->procNum = $procNum;
66+
return $this;
67+
}
68+
}

0 commit comments

Comments
 (0)