Skip to content

Commit bdd8329

Browse files
committed
feat(Concerns): Add Makeable trait for object creation
- Introduce Makeable trait to standardize object creation - Provide create() and make() methods for instantiating objects - Enhance code reusability and maintainability in the Soar class - Remove redundant create() method from Soar class to streamline functionality
1 parent 425c45a commit bdd8329

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"spatie/pest-plugin-snapshots": "^1.1 || ^2.0",
6060
"spaze/phpstan-disallowed-calls": "^4.2",
6161
"symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
62-
"vimeo/psalm": "^5.26 || ^6.0"
62+
"vimeo/psalm": "^4.0 || ^5.0 || ^6.0"
6363
},
6464
"suggest": {
6565
"symfony/var-dumper": "Required to use the the trait [WithDumpable]."

src/Concerns/HasSudoPassword.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function getSudoPassword(): ?string
2929

3030
/**
3131
* @noinspection PhpLanguageLevelInspection
32-
* @noinspection PhpMultipleClassDeclarationsInspection
3332
*/
3433
public function setSudoPassword(
3534
#[\SensitiveParameter]

src/Concerns/Makeable.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2019-2025 guanguans<ityaozm@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*
11+
* @see https://github.com/guanguans/soar-php
12+
*/
13+
14+
namespace Guanguans\SoarPHP\Concerns;
15+
16+
trait Makeable
17+
{
18+
public static function create(...$parameters): self
19+
{
20+
return static::make(...$parameters);
21+
}
22+
23+
public static function make(...$parameters): self
24+
{
25+
return new static(...$parameters);
26+
}
27+
}

src/Soar.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Guanguans\SoarPHP\Concerns\HasOptions;
1919
use Guanguans\SoarPHP\Concerns\HasSoarBinary;
2020
use Guanguans\SoarPHP\Concerns\HasSudoPassword;
21+
use Guanguans\SoarPHP\Concerns\Makeable;
2122
use Guanguans\SoarPHP\Concerns\WithDumpable;
2223
use Guanguans\SoarPHP\Concerns\WithRunable;
2324

@@ -28,6 +29,7 @@ class Soar implements Contracts\Soar
2829
use HasOptions;
2930
use HasSoarBinary;
3031
use HasSudoPassword;
32+
use Makeable;
3133
use WithDumpable;
3234
use WithRunable;
3335

@@ -37,11 +39,6 @@ public function __construct(array $options = [], ?string $soarBinary = null)
3739
$this->setSoarBinary($soarBinary ?? $this->defaultSoarBinary());
3840
}
3941

40-
public static function create(array $options = [], ?string $soarBinary = null): self
41-
{
42-
return new static($options, $soarBinary);
43-
}
44-
4542
/**
4643
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
4744
*/

0 commit comments

Comments
 (0)