Skip to content

Commit

Permalink
Merge pull request #259 from Baptouuuu/modernize-code
Browse files Browse the repository at this point in the history
"Modernize" codebase
  • Loading branch information
mnapoli committed Sep 28, 2020
2 parents 5fd8e84 + 95d7137 commit c168d0b
Show file tree
Hide file tree
Showing 64 changed files with 492 additions and 332 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ before_script:

script:
- vendor/bin/phpunit
- vendor/bin/psalm

after_success:
- if [ "$DEPLOY_WEBSITE" = "true" ]; then ./travis-prepare-release.sh && bin/couscous travis-auto-deploy; fi;
Expand Down
1 change: 1 addition & 0 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env php
<?php
declare(strict_types = 1);
/**
* Generates the PHAR archive.
*
Expand Down
1 change: 1 addition & 0 deletions bin/couscous
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env php
<?php
declare(strict_types = 1);
/**
* Runs Couscous.
*
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
},
"require-dev": {
"phpunit/phpunit": "~7.5",
"squizlabs/php_codesniffer": "^3.3"
"squizlabs/php_codesniffer": "^3.3",
"vimeo/psalm": "^3.16"
},
"config": {
"platform": {
"php": "7.1"
"php": "7.1.3"
}
}
}
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Yes. In your template directory. Add a file called `twig.php` with the following
```php
<?php

use Twig\Environment;
use Twig_Environment as Environment;

// Use "include_once" since this file may be called multiple times
include_once dirname(__DIR__).'/Twig/MyTwigExtension.php';
Expand Down
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
7 changes: 5 additions & 2 deletions src/Application/Cli/ClearCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace Couscous\Application\Cli;

Expand Down Expand Up @@ -28,14 +29,14 @@ public function __construct(Filesystem $filesystem)
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setName('clear')
->setDescription('Clear all files generated by Couscous');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$dir = getcwd().'/.couscous';

Expand All @@ -45,5 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$output->writeln('<comment>Nothing to clear</comment>');
}

return 0;
}
}
12 changes: 10 additions & 2 deletions src/Application/Cli/DeployCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace Couscous\Application\Cli;

Expand Down Expand Up @@ -53,7 +54,7 @@ public function __construct(Generator $generator, Deployer $deployer, Filesystem
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
try {
$remoteUrl = $this->git->getRemoteUrl();
Expand Down Expand Up @@ -95,11 +96,15 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string */
$sourceDirectory = $input->getArgument('source');
/** @var string */
$repositoryUrl = $input->getOption('repository');
/** @var ?string */
$targetBranch = $input->getOption('branch');
/** @var array */
$cliConfig = $input->getOption('config');

$project = new Project($sourceDirectory, getcwd().'/.couscous/generated');
Expand All @@ -111,12 +116,15 @@ protected function execute(InputInterface $input, OutputInterface $output)

// If no branch was provided, use the configured one or the default
if (!$targetBranch) {
/** @var string */
$targetBranch = isset($project->metadata['branch']) ? $project->metadata['branch'] : 'gh-pages';
}

$output->writeln('');

// Deploy it
$this->deployer->deploy($project, $output, $repositoryUrl, $targetBranch);

return 0;
}
}
14 changes: 11 additions & 3 deletions src/Application/Cli/GenerateCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace Couscous\Application\Cli;

Expand Down Expand Up @@ -29,7 +30,7 @@ public function __construct(Generator $generator)
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setName('generate')
Expand All @@ -56,14 +57,21 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string */
$source = $input->getArgument('source');
/** @var string */
$target = $input->getOption('target');
/** @var array */
$cliConfig = $input->getOption('config');

$project = new Project($input->getArgument('source'), $input->getOption('target'));
$project = new Project($source, $target);

$project->metadata['cliConfig'] = $cliConfig;

$this->generator->generate($project, $output);

return 0;
}
}
22 changes: 13 additions & 9 deletions src/Application/Cli/InitTemplateCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types = 1);

namespace Couscous\Application\Cli;

Expand All @@ -14,7 +15,7 @@
*/
class InitTemplateCommand extends Command
{
protected function configure()
protected function configure(): void
{
$this
->setName('init:template')
Expand All @@ -33,13 +34,16 @@ protected function configure()
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$fileExtension = '.twig';

/** @var string */
$dirName = $input->getArgument('directory');
$directory = getcwd().'/'.$dirName.'/';
$templateName = $input->getArgument('template_name').$fileExtension;
/** @var string */
$templateName = $input->getArgument('template_name');
$templateName = $templateName.$fileExtension;

$fileLocation = $directory.$templateName;
$fileExists = file_exists($fileLocation);
Expand All @@ -53,12 +57,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>That template exists at '.$fileLocation.', so nothing has been changed.</error>');
$output->writeln('<error>Try another name!</error>');

return;
return 1;
}

if (!$fileExists) {
$output->writeln('<comment>Initialising template.</comment>');
$template = <<<'HTML'
$output->writeln('<comment>Initialising template.</comment>');
$template = <<<'HTML'
<!DOCTYPE html>
<html>
<head>
Expand All @@ -85,7 +88,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
</body>
</html>
HTML;
file_put_contents($fileLocation, $template);
}
file_put_contents($fileLocation, $template);

return 0;
}
}
Loading

0 comments on commit c168d0b

Please sign in to comment.