Skip to content

Commit b636c88

Browse files
committed
wip
1 parent 24cbbb1 commit b636c88

31 files changed

+293
-1245
lines changed

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
"illuminate/pipeline": "^5.6|^6.0|^7.0|^8.0|^9.0"
3131
},
3232
"require-dev": {
33-
"orchestra/testbench": "^6.0",
34-
"phpunit/phpunit": "^9.0",
33+
"laravel/pint": "^1.2",
3534
"mockery/mockery": "^1.4.4",
36-
"laravel/pint": "^1.2"
35+
"orchestra/testbench": "^6.0",
36+
"pestphp/pest": "^1.22",
37+
"pestphp/pest-plugin-mock": "^1.0",
38+
"phpunit/phpunit": "^9.0"
3739
},
3840
"autoload": {
3941
"psr-4": {
@@ -50,15 +52,18 @@
5052
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
5153
},
5254
"config": {
53-
"sort-packages": true
55+
"sort-packages": true,
56+
"allow-plugins": {
57+
"pestphp/pest-plugin": true
58+
}
5459
},
5560
"extra": {
5661
"laravel": {
5762
"providers": [
5863
"Igorsgm\\GitHooks\\GitHooksServiceProvider"
5964
],
6065
"aliases": {
61-
"GitHooks": "Igorsgm\\GitHooks\\GitHooksFacade"
66+
"GitHooks": "Igorsgm\\GitHooks\\Facades\\GitHooks"
6267
}
6368
}
6469
},

phpunit.xml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
54
bootstrap="vendor/autoload.php"
65
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false"
12-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
13-
<coverage>
14-
<include>
15-
<directory suffix=".php">./src</directory>
16-
</include>
17-
</coverage>
6+
>
187
<testsuites>
19-
<testsuite name="Unit">
8+
<testsuite name="Test Suite">
209
<directory suffix="Test.php">./tests</directory>
2110
</testsuite>
2211
</testsuites>
12+
<coverage processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./app</directory>
15+
<directory suffix=".php">./src</directory>
16+
</include>
17+
</coverage>
2318
</phpunit>

src/Console/Commands/PreCommit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Igorsgm\GitHooks\Contracts\HookCommand;
66
use Igorsgm\GitHooks\Exceptions\HookFailException;
7+
use Igorsgm\GitHooks\Facades\GitHooks;
78
use Igorsgm\GitHooks\Git\ChangedFiles;
8-
use Igorsgm\GitHooks\Git\GitHelper;
99
use Igorsgm\GitHooks\Traits\WithPipeline;
1010
use Illuminate\Console\Command;
1111

@@ -45,7 +45,7 @@ public function handle()
4545
try {
4646
$this->sendChangedFilesThroughHooks(
4747
new ChangedFiles(
48-
GitHelper::getListOfChangedFiles()
48+
GitHooks::getListOfChangedFiles()
4949
)
5050
);
5151
} catch (HookFailException $e) {

src/GitHooksFacade.php renamed to src/Facades/GitHooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace Igorsgm\GitHooks;
3+
namespace Igorsgm\GitHooks\Facades;
44

55
use Illuminate\Support\Facades\Facade;
66

77
/**
88
* @see \Igorsgm\GitHooks\GitHooks
99
*/
10-
class GitHooksFacade extends Facade
10+
class GitHooks extends Facade
1111
{
1212
/**
1313
* Get the registered name of the component.

src/GitHooks.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace Igorsgm\GitHooks;
44

55
use Exception;
6+
use Igorsgm\GitHooks\Traits\GitHelper;
67

78
class GitHooks
89
{
10+
use GitHelper;
11+
912
/**
1013
* Get all supported git hooks
1114
*/

src/Git/GitHelper.php renamed to src/Traits/GitHelper.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
<?php
22

3-
namespace Igorsgm\GitHooks\Git;
3+
namespace Igorsgm\GitHooks\Traits;
44

5-
use Igorsgm\GitHooks\Traits\ProcessHelper;
65
use Symfony\Component\Process\Exception\ProcessFailedException;
76

8-
class GitHelper
7+
trait GitHelper
98
{
109
use ProcessHelper;
1110

1211
/**
1312
* @return string
1413
*/
15-
public static function getListOfChangedFiles()
14+
public function getListOfChangedFiles()
1615
{
17-
return self::execAndGetCommandOutput('git status --short');
16+
return $this->runCommandAndGetOutput('git status --short');
1817
}
1918

2019
/**
2120
* @return string
2221
*/
23-
public static function getLastCommitFromLog()
22+
public function getLastCommitFromLog()
2423
{
25-
return self::execAndGetCommandOutput('git log -1 HEAD');
24+
return $this->runCommandAndGetOutput('git log -1 HEAD');
2625
}
2726

2827
/**
2928
* @param string|array $commands
3029
* @return string
3130
*/
32-
private static function execAndGetCommandOutput($commands)
31+
private function runCommandAndGetOutput($commands)
3332
{
34-
$process = self::execCommands($commands);
33+
$process = $this->runCommands($commands);
3534

3635
if (! $process->isSuccessful()) {
3736
throw new ProcessFailedException($process);
@@ -46,7 +45,7 @@ private static function execAndGetCommandOutput($commands)
4645
* @param string $filePath
4746
* @return string
4847
*/
49-
public static function getCommitMessageContentFromFile(string $filePath): string
48+
public function getCommitMessageContentFromFile(string $filePath): string
5049
{
5150
return file_get_contents($filePath);
5251
}
@@ -57,7 +56,7 @@ public static function getCommitMessageContentFromFile(string $filePath): string
5756
* @param string $path
5857
* @param string $message
5958
*/
60-
public static function updateCommitMessageContentInFile(string $path, string $message): void
59+
public function updateCommitMessageContentInFile(string $path, string $message): void
6160
{
6261
file_put_contents($path, $message);
6362
}

src/Traits/ProcessHelper.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,6 @@ public function runCommands($commands, $params = [])
6161
return $process;
6262
}
6363

64-
/**
65-
* Static alias for runCommands.
66-
*
67-
* @param array|string $commands
68-
* @param array $params
69-
* @return Process
70-
*/
71-
public static function execCommands($commands, $params = [])
72-
{
73-
return (new self)->runCommands($commands, $params);
74-
}
75-
7664
/**
7765
* @param array $commands
7866
* @param callable $callback

src/Traits/WithCommitLog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Igorsgm\GitHooks\Traits;
44

55
use Igorsgm\GitHooks\Exceptions\HookFailException;
6-
use Igorsgm\GitHooks\Git\GitHelper;
6+
use Igorsgm\GitHooks\Facades\GitHooks;
77
use Igorsgm\GitHooks\Git\Log;
88

99
trait WithCommitLog
@@ -20,7 +20,7 @@ public function handle()
2020
try {
2121
$this->sendLogCommitThroughHooks(
2222
new Log(
23-
GitHelper::getLastCommitFromLog()
23+
GitHooks::getLastCommitFromLog()
2424
)
2525
);
2626
} catch (HookFailException $e) {

src/Traits/WithCommitMessage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use Closure;
66
use Igorsgm\GitHooks\Exceptions\HookFailException;
7+
use Igorsgm\GitHooks\Facades\GitHooks;
78
use Igorsgm\GitHooks\Git\ChangedFiles;
89
use Igorsgm\GitHooks\Git\CommitMessage;
9-
use Igorsgm\GitHooks\Git\GitHelper;
1010

1111
trait WithCommitMessage
1212
{
@@ -18,15 +18,15 @@ trait WithCommitMessage
1818
public function handle()
1919
{
2020
try {
21-
$message = GitHelper::getCommitMessageContentFromFile(
21+
$message = GitHooks::getCommitMessageContentFromFile(
2222
$this->getMessagePath()
2323
);
2424

2525
$this->sendMessageThroughHooks(
2626
new CommitMessage(
2727
$message,
2828
new ChangedFiles(
29-
GitHelper::getListOfChangedFiles()
29+
GitHooks::getListOfChangedFiles()
3030
)
3131
)
3232
);
@@ -67,7 +67,7 @@ protected function sendMessageThroughHooks(CommitMessage $message): void
6767
protected function storeMessage(): Closure
6868
{
6969
return function (CommitMessage $message) {
70-
GitHelper::updateCommitMessageContentInFile(
70+
GitHooks::updateCommitMessageContentInFile(
7171
$this->getMessagePath(),
7272
(string) $message
7373
);

0 commit comments

Comments
 (0)