Skip to content

Commit a4b4783

Browse files
committed
Refactor helpers.php
1 parent cc39b3b commit a4b4783

File tree

5 files changed

+6
-62
lines changed

5 files changed

+6
-62
lines changed

recipe/provision/nodejs.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Deployer;
44

55
use function Deployer\Support\escape_shell_argument;
6-
use function Deployer\Support\starts_with;
76

87
set('node_version', '23.x');
98

@@ -16,9 +15,9 @@
1615
}
1716
$arch = run('uname -m');
1817

19-
if ($arch === 'arm' || starts_with($arch, 'armv7')) {
18+
if ($arch === 'arm' || str_starts_with($arch, 'armv7')) {
2019
$filename = 'fnm-arm32';
21-
} elseif (starts_with($arch, 'aarch') || starts_with($arch, 'armv8')) {
20+
} elseif (str_starts_with($arch, 'aarch') || str_starts_with($arch, 'armv8')) {
2221
$filename = 'fnm-arm64';
2322
} else {
2423
$filename = 'fnm-linux';

src/Command/MainCommand.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Deployer\Command;
1212

13-
use Deployer\Configuration;
1413
use Deployer\Deployer;
1514
use Deployer\Exception\Exception;
1615
use Deployer\Exception\GracefulShutdownException;
@@ -22,9 +21,6 @@
2221
use Symfony\Component\Console\Input\InputOption as Option;
2322
use Symfony\Component\Console\Output\OutputInterface as Output;
2423

25-
use function Deployer\Support\find_config_line;
26-
use function Deployer\warning;
27-
2824
class MainCommand extends SelectCommand
2925
{
3026
use CustomOption;

src/Documentation/DocGen.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use RecursiveRegexIterator;
1616
use RegexIterator;
1717

18-
use function Deployer\Support\str_contains as str_contains;
19-
2018
class DocGen
2119
{
2220
/**

src/Support/helpers.php

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010

1111
namespace Deployer\Support;
1212

13-
/**
14-
* Flatten array
15-
*
16-
* @param array $array
17-
* @return array
18-
*/
19-
function array_flatten(array $array)
13+
function array_flatten(array $array): array
2014
{
2115
$flatten = [];
2216
array_walk_recursive($array, function ($value) use (&$flatten) {
@@ -31,13 +25,8 @@ function array_flatten(array $array)
3125
* 1. scalar values are overridden
3226
* 2. array values are extended uniquely if all keys are numeric
3327
* 3. all other array values are merged
34-
*
35-
* @param array $original
36-
* @param array $override
37-
* @return array
38-
* @see http://stackoverflow.com/a/36366886/6812729
3928
*/
40-
function array_merge_alternate(array $original, array $override)
29+
function array_merge_alternate(array $original, array $override): array
4130
{
4231
foreach ($override as $key => $value) {
4332
if (isset($original[$key])) {
@@ -65,26 +54,6 @@ function array_merge_alternate(array $original, array $override)
6554
return $original;
6655
}
6756

68-
/**
69-
* Determines if the given string contains the given value.
70-
*/
71-
function str_contains(string $haystack, string $needle): bool
72-
{
73-
return strpos($haystack, $needle) !== false;
74-
}
75-
76-
/**
77-
* Checks if string stars with given prefix.
78-
*/
79-
function starts_with(string $string, string $prefix): bool
80-
{
81-
$len = strlen($prefix);
82-
return (substr($string, 0, $len) === $prefix);
83-
}
84-
85-
/**
86-
* This function used for create environment string.
87-
*/
8857
function env_stringify(array $array): string
8958
{
9059
return implode(' ', array_map(
@@ -96,11 +65,7 @@ function ($key, $value) {
9665
));
9766
}
9867

99-
/**
100-
* Check if var is closure.
101-
* @param mixed $var
102-
*/
103-
function is_closure($var): bool
68+
function is_closure(mixed $var): bool
10469
{
10570
return is_object($var) && ($var instanceof \Closure);
10671
}
@@ -131,7 +96,7 @@ function normalize_line_endings(string $string): string
13196
*/
13297
function parse_home_dir(string $path): string
13398
{
134-
if ('~' === $path || 0 === strpos($path, '~/')) {
99+
if ('~' === $path || str_starts_with($path, '~/')) {
135100
if (isset($_SERVER['HOME'])) {
136101
$home = $_SERVER['HOME'];
137102
} elseif (isset($_SERVER['HOMEDRIVE'], $_SERVER['HOMEPATH'])) {
@@ -156,18 +121,6 @@ function find_line_number(string $source, string $string): int
156121
return 1;
157122
}
158123

159-
function find_config_line(string $source, string $name): \Generator
160-
{
161-
foreach (explode(PHP_EOL, $source) as $n => $line) {
162-
if (preg_match("/\(['\"]{$name}['\"]/", $line)) {
163-
yield [$n + 1, $line];
164-
}
165-
if (preg_match("/\s{$name}:/", $line)) {
166-
yield [$n + 1, $line];
167-
}
168-
}
169-
}
170-
171124
function colorize_host(string $alias): string
172125
{
173126
if (defined('NO_ANSI')) {

src/functions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434

3535
use function Deployer\Support\array_merge_alternate;
3636
use function Deployer\Support\env_stringify;
37-
use function Deployer\Support\escape_shell_argument;
3837
use function Deployer\Support\is_closure;
39-
use function Deployer\Support\str_contains;
4038

4139
/**
4240
* Defines a host or hosts.

0 commit comments

Comments
 (0)