Skip to content

Commit 27bfc5f

Browse files
committed
Added first tests and minor refactorings
1 parent 0121a93 commit 27bfc5f

16 files changed

+305
-121
lines changed

src/Command/Recipes/RecipeRepoManagerCommand.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@
2525
* @package App\Command\Recipes
2626
* @author moay <[email protected]>
2727
*/
28-
abstract class RecipeRepoManagerCommand extends Command implements RecipeRepoManagerCommandInterface
28+
abstract class RecipeRepoManagerCommand extends Command
2929
{
3030
const ACTION_NAMESPACE = 'recipes:';
3131

3232
/** @var RecipeRepoManager */
3333
private $repoManager;
3434

35+
/** @var string */
36+
protected $action;
37+
38+
/** @var string */
39+
protected $description;
40+
3541
/**
3642
* RecipesInitializeCommand constructor.
3743
* @param RecipeRepoManager $repoManager
@@ -46,13 +52,13 @@ public function __construct(RecipeRepoManager $repoManager)
4652
protected function configure()
4753
{
4854
$this
49-
->setName(self::ACTION_NAMESPACE . $this->getAction())
50-
->setDescription($this->getDescription());
55+
->setName(self::ACTION_NAMESPACE . $this->action)
56+
->setDescription($this->description);
5157

5258
$description = sprintf(
5359
'%s a single repo by selecting \'private\', \'official\' or \'contrib\'. Don\'t select any in order to %s all configured repos.',
54-
ucfirst($this->getAction()),
55-
$this->getAction()
60+
ucfirst($this->action),
61+
$this->action
5662
);
5763

5864
$this->addArgument('repo', InputArgument::IS_ARRAY, $description, []);
@@ -83,8 +89,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8389
} else {
8490
if ($this->repoManager->isConfiguredByDirName($repo)) {
8591
try {
86-
$this->repoManager->executeOnRepo($this->getAction(), $repo);
87-
$actionPast = $this->getAction() == 'reset' ? 'resetted' : $this->getAction() . 'd';
92+
$this->repoManager->executeOnRepo($this->action, $repo);
93+
$actionPast = $this->action === 'reset' ? 'resetted' : $this->action . 'd';
8894
$io->success(sprintf('%s recipes repo %s.', ucfirst($repo), $actionPast));
8995
} catch (RecipeRepoManagerException $e) {
9096
$io->error($e->getMessage());
@@ -94,6 +100,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
94100
}
95101
}
96102
}
97-
98103
}
99104
}

src/Command/Recipes/RecipeRepoManagerCommandInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Command/Recipes/RecipesInitializeCommand.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,9 @@
1919
class RecipesInitializeCommand extends RecipeRepoManagerCommand
2020
{
2121
/** @var string */
22-
private $action = 'initialize';
22+
protected $action = 'initialize';
2323

2424
/** @var string */
25-
private $description = 'Initializes local recipe repos from remote repo';
25+
protected $description = 'Initializes local recipe repos from remote repo';
2626

27-
/**
28-
* @return string
29-
*/
30-
public function getAction()
31-
{
32-
return $this->action;
33-
}
34-
35-
/**
36-
* @return string
37-
*/
38-
public function getDescription()
39-
{
40-
return $this->description;
41-
}
4227
}

src/Command/Recipes/RecipesRemoveCommand.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,8 @@
1919
class RecipesRemoveCommand extends RecipeRepoManagerCommand
2020
{
2121
/** @var string */
22-
private $action = 'remove';
22+
protected $action = 'remove';
2323

2424
/** @var string */
25-
private $description = 'Deletes local recipe repos';
26-
27-
/**
28-
* @return string
29-
*/
30-
public function getAction()
31-
{
32-
return $this->action;
33-
}
34-
35-
/**
36-
* @return string
37-
*/
38-
public function getDescription()
39-
{
40-
return $this->description;
41-
}
25+
protected $description = 'Deletes local recipe repos';
4226
}

src/Command/Recipes/RecipesResetCommand.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,8 @@
1919
class RecipesResetCommand extends RecipeRepoManagerCommand
2020
{
2121
/** @var string */
22-
private $action = 'reset';
22+
protected $action = 'reset';
2323

2424
/** @var string */
25-
private $description = 'Resets local recipe repos by deleting and reinitalizing from remote repo';
26-
27-
/**
28-
* @return string
29-
*/
30-
public function getAction()
31-
{
32-
return $this->action;
33-
}
34-
35-
/**
36-
* @return string
37-
*/
38-
public function getDescription()
39-
{
40-
return $this->description;
41-
}
25+
protected $description = 'Resets local recipe repos by deleting and reinitalizing from remote repo';
4226
}

src/Command/Recipes/RecipesUpdateCommand.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,8 @@
1919
class RecipesUpdateCommand extends RecipeRepoManagerCommand
2020
{
2121
/** @var string */
22-
private $action = 'update';
22+
protected $action = 'update';
2323

2424
/** @var string */
25-
private $description = 'Updates local recipe repos to match the current remote repo';
26-
27-
/**
28-
* @return string
29-
*/
30-
public function getAction()
31-
{
32-
return $this->action;
33-
}
34-
35-
/**
36-
* @return string
37-
*/
38-
public function getDescription()
39-
{
40-
return $this->description;
41-
}
25+
protected $description = 'Updates local recipe repos to match the current remote repo';
4226
}

src/Command/System/SystemStatusCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function configure()
4545
->setDescription('Provides an overview over the system status');
4646
}
4747

48+
/**
49+
* @param InputInterface $input
50+
* @param OutputInterface $output
51+
* @return void
52+
*/
4853
public function execute(InputInterface $input, OutputInterface $output)
4954
{
5055
$io = new SymfonyStyle($input, $output);

src/Service/Compiler/LocalRecipeCompiler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public function __construct(RecipeRepoManager $repoManager)
4343
/**
4444
* @return Recipe[]
4545
*/
46-
public function getLocalRecipes() {
46+
public function getLocalRecipes()
47+
{
4748
if (count($this->recipes) == 0) {
48-
$this->loadLocalRecipes();
49+
$this->loadLocalRecipes();
4950
}
5051

5152
return $this->recipes;

src/Service/Compiler/PackagesCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private function getPackageLocks(array $requestedPackages)
4343
{
4444
$locks = [];
4545
foreach ($requestedPackages as $package) {
46-
$locks[join('/', [$package['author'], $package['package']])] = ['version' => $package['version']];
46+
$locks[implode('/', [$package['author'], $package['package']])] = ['version' => $package['version']];
4747
}
4848
return $locks;
4949
}
@@ -65,7 +65,7 @@ private function getManifests(array $localRecipes, array $officialResponse)
6565
'files' => $this->getRecipeFiles($recipe),
6666
'origin' => $recipe->getOfficialPackageName() . ':' . $recipe->getVersion() . '@private:master',
6767
'not_installable' => $recipe->isManifestValid() === false,
68-
'is_contrib' => $recipe->getRepoSlug() == 'contrib'
68+
'is_contrib' => $recipe->getRepoSlug() === 'contrib'
6969
];
7070

7171
if (empty($manifest['files'])) {

src/Service/OfficialEndpointProxy.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function __construct(
5858
* Provides a proxy for the aliases.json call, which provides official Symfony aliases.
5959
*
6060
* @return array
61+
* @throws \Exception
62+
* @throws \Http\Client\Exception
6163
*/
6264
public function getAliases()
6365
{
@@ -69,6 +71,8 @@ public function getAliases()
6971
* Provides a proxy for the versions.json call, which provides version information for Symfony.
7072
*
7173
* @return array
74+
* @throws \Exception
75+
* @throws \Http\Client\Exception
7276
*/
7377
public function getVersions()
7478
{
@@ -81,6 +85,8 @@ public function getVersions()
8185
*
8286
* @param string $packagesRequestString
8387
* @return array|string
88+
* @throws \Exception
89+
* @throws \Http\Client\Exception
8490
*/
8591
public function getPackages(string $packagesRequestString)
8692
{
@@ -91,6 +97,8 @@ public function getPackages(string $packagesRequestString)
9197
/**
9298
* @param Request $request
9399
* @return array|string
100+
* @throws \Exception
101+
* @throws \Http\Client\Exception
94102
*/
95103
private function getDecodedResponse(Request $request)
96104
{

src/Service/Provider/AliasesProvider.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@ public function provideAliases()
8080
*/
8181
public function getLocalAliases()
8282
{
83-
$aliases = [];
84-
8583
if ($this->cache->has(self::LOCAL_ALIASES_CACHE_KEY)) {
8684
return $this->cache->get(self::LOCAL_ALIASES_CACHE_KEY);
8785
}
8886

87+
$aliases = [];
8988
$recipes = $this->recipeCompiler->getLocalRecipes();
9089

9190
foreach ($recipes as $recipe) {
@@ -121,13 +120,13 @@ public function getLocalAliases()
121120
private function resolveAliasConflict(Recipe $recipe1, Recipe $recipe2)
122121
{
123122
if ($recipe1->getRepoSlug() != $recipe2->getRepoSlug()) {
124-
if ($recipe1->getRepoSlug() == 'private') {
123+
if ($recipe1->getRepoSlug() === 'private') {
125124
return $recipe1;
126125
}
127-
if ($recipe2->getRepoSlug() == 'private') {
126+
if ($recipe2->getRepoSlug() === 'private') {
128127
return $recipe2;
129128
}
130-
if ($recipe1->getRepoSlug() == 'official') {
129+
if ($recipe1->getRepoSlug() === 'official') {
131130
return $recipe1;
132131
}
133132
return $recipe2;

src/Service/Provider/PackagesProvider.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function __construct(
5757
*
5858
* @param string $packagesRequestString
5959
* @return array
60+
* @throws \Exception
61+
* @throws \Http\Client\Exception
6062
*/
6163
public function providePackages(string $packagesRequestString)
6264
{
@@ -91,6 +93,8 @@ private function getLocalRecipes(array $requestedPackages)
9193
/**
9294
* @param string $packagesRequestString
9395
* @return array|string
96+
* @throws \Exception
97+
* @throws \Http\Client\Exception
9498
*/
9599
private function getOfficialProxyResponse(string $packagesRequestString)
96100
{
@@ -111,13 +115,13 @@ private function getLocalRecipe(array $package)
111115
usort($localRecipes, function (Recipe $recipe1, Recipe $recipe2) {
112116
if ($recipe1->getVersion() == $recipe2->getVersion()) {
113117
if ($recipe1->getRepoSlug() != $recipe2->getRepoSlug()) {
114-
if ($recipe1->getRepoSlug() == 'private') {
118+
if ($recipe1->getRepoSlug() === 'private') {
115119
return -1;
116120
}
117-
if ($recipe2->getRepoSlug() == 'private') {
121+
if ($recipe2->getRepoSlug() === 'private') {
118122
return 1;
119123
}
120-
if ($recipe1->getRepoSlug() == 'official') {
124+
if ($recipe1->getRepoSlug() === 'official') {
121125
return -1;
122126
}
123127
return 1;

src/Service/RecipeRepoManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\RecipeRepo\OfficialRecipeRepo;
1717
use App\RecipeRepo\PrivateRecipeRepo;
1818
use App\RecipeRepo\RecipeRepo;
19+
use Cz\Git\GitException;
1920
use Psr\Log\LoggerInterface;
2021

2122
/**
@@ -90,6 +91,7 @@ public function isConfiguredByDirName(string $repoDirName)
9091
* @param string $action
9192
* @param string $repoDirName
9293
* @throws RecipeRepoManagerException
94+
* @throws GitException
9395
*/
9496
public function executeOnRepo(string $action, string $repoDirName)
9597
{

0 commit comments

Comments
 (0)