Skip to content

Commit 697c84e

Browse files
committed
Code cleanup
1 parent 4759db7 commit 697c84e

20 files changed

+61
-63
lines changed

src/SystemCtl.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
class SystemCtl
1919
{
2020
/** @var string systemctl binary path */
21-
public static $binary = '/bin/systemctl';
21+
private static $binary = '/bin/systemctl';
2222

2323
/** @var int timeout for commands */
2424
private static $timeout = 3;
2525

26+
/** @var CommandDispatcherInterface */
27+
private $commandDispatcher;
28+
2629
public const AVAILABLE_UNITS = [
2730
Service::UNIT,
2831
'socket',
@@ -42,8 +45,6 @@ class SystemCtl
4245
Timer::UNIT,
4346
];
4447

45-
private $commandDispatcher;
46-
4748
/**
4849
* Change systemctl binary
4950
*

src/Template/AbstractUnitTemplate.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ public function __construct(string $unitName, string $unitSuffix)
4343
$this->installSection = new InstallSection;
4444
}
4545

46+
/**
47+
* @return AbstractSection
48+
*/
49+
abstract public function getTypeSpecificSection();
50+
4651
/**
4752
* Get all definitions for this template as array
4853
*
4954
* @return array
5055
*/
51-
public function getDefinitions(): array
56+
public function getSections(): array
5257
{
5358
$unitProperties = $this->getUnitSection()->getProperties();
59+
$typeSpecificProperties = $this->getTypeSpecificSection()->getProperties();
5460
$installProperties = $this->getInstallSection()->getProperties();
5561

5662
$definitions = [];
@@ -59,6 +65,10 @@ public function getDefinitions(): array
5965
$definitions['Unit'] = $this->convertProperties($unitProperties);
6066
}
6167

68+
if (!empty($typeSpecificProperties)) {
69+
$definitions[ucfirst($this->getUnitSuffix())] = $this->convertProperties($typeSpecificProperties);
70+
}
71+
6272
if (!empty($installProperties)) {
6373
$definitions['Install'] = $this->convertProperties($installProperties);
6474
}

src/Template/Renderer/PlatesRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public function __construct(Plates\Engine $engine)
3333
*/
3434
public function render(string $templateFile, AbstractUnitTemplate $unitTemplate): string
3535
{
36-
return $this->engine->render($templateFile, ['sections' => $unitTemplate->getDefinitions()]);
36+
return $this->engine->render($templateFile, ['sections' => $unitTemplate->getSections()]);
3737
}
3838
}

src/Template/Section/AbstractSection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ public function getProperties(): array
2828
*/
2929
public function __call($name, $arguments)
3030
{
31-
preg_match('/(?<type>get|set|should)(?<property>.*)/', $name, $match);
31+
preg_match('/(?<type>get|set)(?<property>.*)/', $name, $match);
3232

3333
if (!in_array($match['property'], static::PROPERTIES)) {
3434
throw new PropertyNotSupportedException($match['property'], static::class);
3535
}
3636

3737
if ($match['type'] === 'set') {
3838
$this->properties[$match['property']] = $arguments[0];
39+
3940
return $this;
4041
}
4142

src/Template/Section/ServiceSection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @method string getExecStop()
2323
* @method string getExecReload()
2424
* @method string getRestart()
25-
* @method bool shouldRemainsAfterExit()
25+
* @method bool getRemainsAfterExit()
2626
* @method string getPIDFile()
2727
*
2828
* @package SystemCtl\Template\Section

src/Template/Section/TimerSection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @method string getOnCalendar()
1313
* @method string getUnit()
14-
* @method bool shouldRemainAfterElapse()
14+
* @method bool getRemainAfterElapse()
1515
*
1616
* @package SystemCtl\Template\Section
1717
* @author icanhazstring <[email protected]>

src/Template/ServiceUnitTemplate.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,8 @@ public function getServiceSection(): ServiceSection
3333
/**
3434
* @inheritDoc
3535
*/
36-
public function getDefinitions(): array
36+
public function getTypeSpecificSection()
3737
{
38-
$defintiions = parent::getDefinitions();
39-
$serviceProperties = $this->getServiceSection()->getProperties();
40-
41-
if (!empty($serviceProperties)) {
42-
$defintiions[ucfirst(Service::UNIT)] = $this->convertProperties($serviceProperties);
43-
}
44-
45-
return $defintiions;
38+
return $this->serviceSection;
4639
}
4740
}

src/Template/TimerUnitTemplate.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,8 @@ public function getTimerSection(): TimerSection
3333
/**
3434
* @inheritDoc
3535
*/
36-
public function getDefinitions(): array
36+
public function getTypeSpecificSection()
3737
{
38-
$defintiions = parent::getDefinitions();
39-
$timerProperties = $this->getTimerSection()->getProperties();
40-
41-
if (!empty($timerProperties)) {
42-
$defintiions[ucfirst(Timer::UNIT)] = $this->convertProperties($timerProperties);
43-
}
44-
45-
return $defintiions;
38+
return $this->timerSection;
4639
}
4740
}

tests/Integration/SystemCtlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Class SystemCtlTest
1717
*
18-
* @package SystemCtl\Test\Integration
18+
* @package SystemCtl\Tests\Integration
1919
*/
2020
class SystemCtlTest extends TestCase
2121
{

tests/Unit/Template/Renderer/PlatesRendererTest.php renamed to tests/Integration/Template/Renderer/PlatesRendererTest.php

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

3-
namespace SystemCtl\Test\Unit\Template\Renderer;
3+
namespace SystemCtl\Tests\Integration\Template\Renderer;
44

55
use League\Plates\Engine;
66
use PHPUnit\Framework\TestCase;
@@ -14,7 +14,7 @@
1414
/**
1515
* PlatesRendererTest
1616
*
17-
* @package SystemCtl\Test\Unit\Template\Renderer
17+
* @package SystemCtl\Tests\Unit\Template\Renderer
1818
* @author icanhazstring <[email protected]>
1919
*/
2020
class PlatesRendererTest extends TestCase
@@ -56,10 +56,10 @@ public function testPlatesRenderer()
5656
$this->assertEquals(<<<EOT
5757
[Unit]
5858
Description=TestDescription
59-
[Install]
60-
WantedBy=multi-user.target
6159
[Service]
6260
Type=simple
61+
[Install]
62+
WantedBy=multi-user.target
6363
6464
EOT
6565
, $result);

0 commit comments

Comments
 (0)