Skip to content

Commit

Permalink
Applied fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli authored and StyleCIBot committed Sep 8, 2015
1 parent 7cc5e1c commit f36e5a7
Show file tree
Hide file tree
Showing 53 changed files with 175 additions and 165 deletions.
4 changes: 2 additions & 2 deletions src/Application/Cli/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ protected function configure()

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

if (file_exists($dir)) {
$output->writeln("<comment>Deleting folder $dir</comment>");
$this->filesystem->remove($dir);
} else {
$output->writeln("<comment>Nothing to clear</comment>");
$output->writeln('<comment>Nothing to clear</comment>');
}
}
}
14 changes: 7 additions & 7 deletions src/Application/Cli/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Couscous\Application\Cli;

use Couscous\CommandRunner\Git;
use Couscous\Deployer;
use Couscous\Generator;
use Couscous\Model\Project;
use Couscous\Deployer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -42,10 +42,10 @@ class DeployCommand extends Command

public function __construct(Generator $generator, Deployer $deployer, Filesystem $filesystem, Git $git)
{
$this->generator = $generator;
$this->deployer = $deployer;
$this->generator = $generator;
$this->deployer = $deployer;
$this->filesystem = $filesystem;
$this->git = $git;
$this->git = $git;

parent::__construct();
}
Expand Down Expand Up @@ -92,10 +92,10 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$sourceDirectory = $input->getArgument('source');
$repositoryUrl = $input->getOption('repository');
$targetBranch = $input->getOption('branch');
$repositoryUrl = $input->getOption('repository');
$targetBranch = $input->getOption('branch');

$project = new Project($sourceDirectory, getcwd() . '/.couscous/generated');
$project = new Project($sourceDirectory, getcwd().'/.couscous/generated');

// Generate the website
$this->generator->generate($project, $output);
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Cli/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function configure()
null,
InputOption::VALUE_REQUIRED,
'Target directory in which to generate the files.',
getcwd() . '/.couscous/generated'
getcwd().'/.couscous/generated'
);
}

Expand Down
30 changes: 14 additions & 16 deletions src/Application/Cli/InitTemplateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*
* @author Ross J. Hagan <[email protected]>
*/
class InitTemplateCommand extends Command {

class InitTemplateCommand extends Command
{
protected function configure()
{
$this
Expand All @@ -35,28 +35,28 @@ protected function configure()

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

$fileExtension = '.twig';

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

$fileLocation = $directory . $templateName;
$fileExists = file_exists($fileLocation);
$fileLocation = $directory.$templateName;
$fileExists = file_exists($fileLocation);

if (! file_exists(getcwd() . '/' . $dirName)) {
if (!file_exists(getcwd().'/'.$dirName)) {
$output->writeln('<comment>Creating directory.</comment>');
mkdir(getcwd() . '/' . $dirName);
mkdir(getcwd().'/'.$dirName);
}

if ($fileExists) {
$output->writeln('<error>That template exists at ' . $fileLocation . ', so nothing has been changed.</error>');
$output->writeln('<error>That template exists at '.$fileLocation.', so nothing has been changed.</error>');
$output->writeln('<error>Try another name!</error>');

return;
}

if (! $fileExists) {
if (!$fileExists) {
$output->writeln('<comment>Initialising template.</comment>');
$template = <<<HTML
<!DOCTYPE html>
Expand Down Expand Up @@ -87,7 +87,5 @@ protected function execute(InputInterface $input, OutputInterface $output)
HTML;
file_put_contents($fileLocation, $template);
}

}

}
}
10 changes: 6 additions & 4 deletions src/Application/Cli/PreviewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function configure()
null,
InputOption::VALUE_REQUIRED,
'Target directory in which to generate the files.',
getcwd() . '/.couscous/generated'
getcwd().'/.couscous/generated'
);
}

Expand All @@ -65,8 +65,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (! $this->isSupported()) {
if (!$this->isSupported()) {
$output->writeln('<error>PHP 5.4 or above is required to run the internal webserver</error>');

return 1;
}

Expand Down Expand Up @@ -120,7 +121,7 @@ private function startWebServer(InputInterface $input, OutputInterface $output,
$process = $builder->getProcess();
$process->start();

$output->writeln(sprintf("Server running on <comment>%s</comment>", $input->getArgument('address')));
$output->writeln(sprintf('Server running on <comment>%s</comment>', $input->getArgument('address')));

return $process;
}
Expand All @@ -130,6 +131,7 @@ private function isSupported()
if (version_compare(phpversion(), '5.4.0', '<')) {
return false;
}

return true;
}

Expand All @@ -142,7 +144,7 @@ private function fileListToDisplay(array $files, $sourceDirectory)
$str = implode(', ', $files);

if (strlen($str) > 60) {
$str = substr($str, 0, 60) . '';
$str = substr($str, 0, 60).'';
}

return $str;
Expand Down
15 changes: 9 additions & 6 deletions src/Application/Cli/TravisAutoDeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Couscous\Application\Cli;

use Couscous\CommandRunner\CommandRunner;
use Couscous\Generator;
use Couscous\Deployer;
use Couscous\Generator;
use Couscous\Model\Project;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -36,8 +36,8 @@ class TravisAutoDeployCommand extends Command

public function __construct(Generator $generator, Deployer $deployer, CommandRunner $commandRunner)
{
$this->generator = $generator;
$this->deployer = $deployer;
$this->generator = $generator;
$this->deployer = $deployer;
$this->commandRunner = $commandRunner;

parent::__construct();
Expand Down Expand Up @@ -79,23 +79,25 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$sourceDirectory = $input->getArgument('source');
$repositoryUrl = sprintf('https://%s@%s', getenv('GH_TOKEN'), getenv('GH_REF'));
$targetBranch = $input->getOption('branch');
$repositoryUrl = sprintf('https://%s@%s', getenv('GH_TOKEN'), getenv('GH_REF'));
$targetBranch = $input->getOption('branch');

$repository = new Project($sourceDirectory, getcwd() . '/.couscous/generated');
$repository = new Project($sourceDirectory, getcwd().'/.couscous/generated');

// verify some env variables
$travisBranch = getenv('TRAVIS_BRANCH');

if ($travisBranch !== 'master') {
$output->writeln('<comment>[NOT DEPLOYED] Deploying Couscous only for master branch</comment>');

return;
}

$isPullRequest = (int) getenv('TRAVIS_PULL_REQUEST') > 0 ? true : false;

if ($isPullRequest) {
$output->writeln('<comment>[NOT DEPLOYED] Not deploying Couscous for pull requests</comment>');

return;
}

Expand All @@ -108,6 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$currentPhpVersion = getenv('TRAVIS_PHP_VERSION');
if ($input->getOption('php-version') != $currentPhpVersion) {
$output->writeln('<comment>This version of the documentation is already deployed</comment>');

return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Application/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function createContainer()
{
$builder = new ContainerBuilder();

$builder->addDefinitions(__DIR__ . '/config.php');
$builder->addDefinitions(__DIR__.'/config.php');

$moduleConfigs = new Finder();
$moduleConfigs->files()
->in(__DIR__ . '/../Module')
->in(__DIR__.'/../Module')
->path('/.+/')
->name('config.php');

Expand Down
15 changes: 7 additions & 8 deletions src/Application/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Interop\Container\ContainerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -55,13 +54,13 @@
->constructorParameter('verbosityLevelMap', [
// Custom verbosity map
LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL,
LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE,
LogLevel::DEBUG => OutputInterface::VERBOSITY_VERY_VERBOSE,
LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL,
LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE,
LogLevel::DEBUG => OutputInterface::VERBOSITY_VERY_VERBOSE,
]),

];
5 changes: 3 additions & 2 deletions src/CommandRunner/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ class CommandRunner
/**
* Runs a command.
*
* @throws CommandException When the command exit code is not zero.
*
* @param string $command The command to be executed.
*
* @throws CommandException When the command exit code is not zero.
*
* @return string Output of the command.
*/
public function run($command)
{
exec($command . ' 2>&1', $output, $returnValue);
exec($command.' 2>&1', $output, $returnValue);

$output = implode(PHP_EOL, $output);

Expand Down
1 change: 1 addition & 0 deletions src/CommandRunner/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function push($directory, $branch, $remote = 'origin')

/**
* @param string $remote Remote name
*
* @return string The git URL
*/
public function getRemoteUrl($remote = 'origin')
Expand Down
8 changes: 4 additions & 4 deletions src/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Deployer
public function __construct(Filesystem $filesystem, Git $git)
{
$this->filesystem = $filesystem;
$this->git = $git;
$this->git = $git;
}

/**
Expand All @@ -40,9 +40,9 @@ public function __construct(Filesystem $filesystem, Git $git)
*/
public function deploy(Project $project, OutputInterface $output, $repositoryUrl, $branch)
{
$output->writeln("<comment>Deploying the website</comment>");
$output->writeln('<comment>Deploying the website</comment>');

$directory = $project->targetDirectory;
$directory = $project->targetDirectory;
$tmpDirectory = $this->createTempDirectory();

$this->cloneRepository($output, $repositoryUrl, $tmpDirectory);
Expand Down Expand Up @@ -86,7 +86,7 @@ private function checkoutBranch(OutputInterface $output, $branch, $tmpDirectory)
try {
$this->git->createBranch($tmpDirectory, $branch);
} catch (CommandException $e) {
throw new \RuntimeException("Unable to create the branch '$branch'" . PHP_EOL . $e->getMessage());
throw new \RuntimeException("Unable to create the branch '$branch'".PHP_EOL.$e->getMessage());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class Generator
private $steps;

/**
* @param Filesystem $filesystem
* @param Step[] $steps
* @param Filesystem $filesystem
* @param Step[] $steps
*/
public function __construct(Filesystem $filesystem, array $steps)
{
$this->filesystem = $filesystem;
$this->steps = $steps;
$this->steps = $steps;
}

public function generate(Project $project, OutputInterface $output)
{
$output->writeln(sprintf(
"<comment>Generating %s to %s</comment>",
'<comment>Generating %s to %s</comment>',
$project->sourceDirectory,
$project->targetDirectory
));
Expand Down
4 changes: 2 additions & 2 deletions src/Model/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getBasename()
public function getDirectory()
{
$directory = dirname($this->relativeFilename);
$directory = ($directory === '.') ? '' : $directory . '/';
$directory = ($directory === '.') ? '' : $directory.'/';

return $directory;
}
Expand All @@ -50,7 +50,7 @@ public function getDirectory()
*
* @return string
*/
public abstract function getContent();
abstract public function getContent();

/**
* Returns an indexed array of metadata.
Expand Down
Loading

0 comments on commit f36e5a7

Please sign in to comment.