-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
UseDefaultTemplate.php
57 lines (46 loc) · 1.47 KB
/
UseDefaultTemplate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types = 1);
namespace Couscous\Module\Template\Step;
use Couscous\Model\Project;
use Couscous\Step;
use Symfony\Component\Filesystem\Filesystem;
/**
* Uses the default template if none is configured or included in the repository.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class UseDefaultTemplate implements Step
{
const DEFAULT_TEMPLATE_URL = 'https://github.com/CouscousPHP/Template-Light.git';
/**
* @var Filesystem
*/
private $filesystem;
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}
public function __invoke(Project $project): void
{
if ($this->useRemoteTemplate($project)
|| $this->hasCustomTemplateDirectory($project)
|| $this->hasTemplateDirectory($project)
) {
return;
}
$project->metadata['template.url'] = self::DEFAULT_TEMPLATE_URL;
}
private function useRemoteTemplate(Project $project): bool
{
return $project->metadata['template.url'] !== null;
}
private function hasCustomTemplateDirectory(Project $project): bool
{
return $project->metadata['template.directory'] !== null;
}
private function hasTemplateDirectory(Project $project): bool
{
$templateDirectory = $project->sourceDirectory.'/'.ValidateTemplateDirectory::DEFAULT_TEMPLATE_DIRECTORY;
return $this->filesystem->exists($templateDirectory);
}
}