Skip to content

Commit 1110656

Browse files
Improve type coverage
1 parent 6ffbff8 commit 1110656

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

src/Config/Options.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function __construct(array $options)
4141
/**
4242
* Return a option value
4343
*
44-
* @template T
45-
* @param string $name
46-
* @param T $default
47-
* @return T|null
44+
* @template ProvidedDefault
45+
* @param string $name
46+
* @param ProvidedDefault $default
47+
* @return ProvidedDefault|mixed
4848
*/
4949
public function get(string $name, $default = null)
5050
{
51-
return isset($this->options[$name]) ? $this->options[$name] : $default;
51+
return $this->options[$name] ?? $default;
5252
}
5353

5454
/**

src/Hook/PHP/Action/TestCoverage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ class TestCoverage implements Action
3535
*
3636
* @var string
3737
*/
38-
private $cloverXmlFile;
38+
private string $cloverXmlFile;
3939

4040
/**
4141
* Path to PHPUnit
4242
*
4343
* @var string
4444
*/
45-
private $phpUnit;
45+
private string $phpUnit;
4646

4747
/**
4848
* Minimum coverage in percent
4949
*
5050
* @var int
5151
*/
52-
private $minCoverage;
52+
private int $minCoverage;
5353

5454
/**
5555
* Executes the action.

src/Runner/Hook/PrepareCommitMsg.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class PrepareCommitMsg extends Hook
3636
protected $hook = Hooks::PREPARE_COMMIT_MSG;
3737

3838
/**
39-
* @var string|null
39+
* @var string
4040
*/
41-
private ?string $commentChar;
41+
private string $commentChar;
4242

4343
/**
4444
* Path to commit message file

tests/unit/Mockery.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\MockObject\MockBuilder;
1616
use SebastianFeldmann\Git\Operator\Diff;
1717
use SebastianFeldmann\Git\Operator\Index;
18+
use SebastianFeldmann\Git\Operator\Config;
1819
use SebastianFeldmann\Git\Operator\Info;
1920
use SebastianFeldmann\Git\Operator\Log;
2021
use SebastianFeldmann\Git\Repository;
@@ -98,7 +99,6 @@ public function createGitDiffOperator(array $changedFiles = []): Diff
9899
/**
99100
* Create log operator mock
100101
*
101-
* @param array $changedFiles
102102
* @return \SebastianFeldmann\Git\Operator\Log&\PHPUnit\Framework\MockObject\MockObject
103103
*/
104104
public function createGitLogOperator(): Log
@@ -127,6 +127,16 @@ public function createGitIndexOperator(array $stagedFiles = []): Index
127127
return $operator;
128128
}
129129

130+
/**
131+
* Create config operator mock
132+
*
133+
* @return \SebastianFeldmann\Git\Operator\Config&\PHPUnit\Framework\MockObject\MockObject
134+
*/
135+
public function createGitConfigOperator(): Config
136+
{
137+
return $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
138+
}
139+
130140
/**
131141
* @param $type
132142
* @return \PHPUnit\Framework\MockObject\MockBuilder

tests/unit/Runner/Hook/PrepareCommitMsgTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ public function testRunHookNoMessageException(): void
7373
{
7474
$this->expectException(Exception::class);
7575

76+
$repo = $this->createRepositoryMock();
77+
$configOp = $this->createGitConfigOperator();
78+
$configOp->method('getSafely')->willReturn('#');
79+
$repo->method('getConfigOperator')->willReturn($configOp);
80+
7681
$io = $this->createIOMock();
7782
$config = $this->createConfigMock();
78-
$repo = $this->createRepositoryMock();
7983
$hookConfig = $this->createHookConfigMock();
8084
$actionConfig = $this->createActionConfigMock();
8185
$actionConfig->method('getAction')->willReturn(Prepare::class);

0 commit comments

Comments
 (0)