Skip to content

Commit 75406e5

Browse files
committed
Add Utils::isCiDetected
1 parent 2da2a46 commit 75406e5

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ use CodeLts\CliTools\File\AnsiEscapeSequences;
8585

8686
$this->output->writeFormatted(AnsiEscapeSequences::ERASE_TO_LINE_END);
8787
```
88+
89+
### Detect a CI
90+
91+
```php
92+
use CodeLts\CliTools\Utils;
93+
94+
// See supported CIs at https://github.com/OndraM/ci-detector#supported-continuous-integration-servers
95+
96+
Utils::isCiDetected(); // true of false
97+
```

src/ErrorsConsoleStyle.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public function __construct(InputInterface $input, OutputInterface $output)
5555
private function isCiDetected(): bool
5656
{
5757
if ($this->isCiDetected === null) {
58-
$ciDetector = new CiDetector();
59-
$this->isCiDetected = $ciDetector->isCiDetected();
58+
$this->isCiDetected = Utils::isCiDetected();
6059
}
6160

6261
return $this->isCiDetected;

src/OutputFormat.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ public static function checkOutputFormatIsValid(string $outputFormat): bool
5959
if (in_array($outputFormat, OutputFormat::VALID_OUTPUT_FORMATS)) {
6060
return true;
6161
}
62-
throw new FormatNotFoundException(
63-
sprintf(
64-
'Error formatter "%s" not found. Available error formatters are: %s',
65-
$outputFormat,
66-
implode(', ', OutputFormat::VALID_OUTPUT_FORMATS)
67-
)
68-
);
62+
throw new FormatNotFoundException($outputFormat);
6963
}
7064

7165
/**

src/Utils.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CodeLts\CliTools;
6+
7+
use OndraM\CiDetector\CiDetector;
8+
9+
/**
10+
* Some utilities
11+
*/
12+
class Utils
13+
{
14+
public static function isCiDetected(): bool
15+
{
16+
$ciDetector = new CiDetector();
17+
return $ciDetector->isCiDetected();
18+
}
19+
}

tests/UtilsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CodeLts\CliTools\Tests;
6+
7+
use CodeLts\CliTools\Utils;
8+
9+
class UtilsTest extends AbstractTestCase
10+
{
11+
public function testIsCiDetected(): void
12+
{
13+
$this->assertIsBool(Utils::isCiDetected());
14+
}
15+
}

0 commit comments

Comments
 (0)