Skip to content

Commit

Permalink
CS Fixer (#1243)
Browse files Browse the repository at this point in the history
* CS Fixer
  • Loading branch information
isometriks committed Jan 24, 2019
1 parent 395bb11 commit 419bb11
Show file tree
Hide file tree
Showing 40 changed files with 470 additions and 427 deletions.
16 changes: 16 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'full_opening_tag' => false,
'yoda_style' => false,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
;
82 changes: 41 additions & 41 deletions Command/BaseBootstrapSymlinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
use Symfony\Component\Filesystem\Filesystem;

/**
* Command to check and create bootstrap symlink into MopaBootstrapBundle
* Command to check and create bootstrap symlink into MopaBootstrapBundle.
*
* @author phiamo <phiamo@googlemail.com>
*/
abstract class BaseBootstrapSymlinkCommand extends ContainerAwareCommand
{
public static $mopaBootstrapBundleName = "mopa/bootstrap-bundle";
public static $mopaBootstrapBundleName = 'mopa/bootstrap-bundle';
public static $targetSuffix = '';
public static $pathName = 'TwitterBootstrap';
/**
Expand All @@ -42,19 +42,19 @@ abstract class BaseBootstrapSymlinkCommand extends ContainerAwareCommand
/**
* Checks symlink's existence.
*
* @param string $symlinkTarget The Target
* @param string $symlinkName The Name
* @param boolean $forceSymlink Force to be a link or throw exception
* @param string $symlinkTarget The Target
* @param string $symlinkName The Name
* @param bool $forceSymlink Force to be a link or throw exception
*
* @return boolean
* @return bool
*
* @throws \Exception
*/
public static function checkSymlink($symlinkTarget, $symlinkName, $forceSymlink = false)
{
if ($forceSymlink && file_exists($symlinkName) && !is_link($symlinkName)) {
if ("link" != filetype($symlinkName)) {
throw new \Exception($symlinkName." exists and is no link!");
if ('link' != filetype($symlinkName)) {
throw new \Exception($symlinkName.' exists and is no link!');
}
} elseif (is_link($symlinkName)) {
$linkTarget = readlink($symlinkName);
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function checkSymlink($symlinkTarget, $symlinkName, $forceSymlink
public static function createSymlink($symlinkTarget, $symlinkName)
{
if (false === @symlink($symlinkTarget, $symlinkName)) {
throw new \Exception("An error occurred while creating symlink".$symlinkName);
throw new \Exception('An error occurred while creating symlink'.$symlinkName);
}
if (false === $target = readlink($symlinkName)) {
throw new \Exception("Symlink $symlinkName points to target $target");
Expand All @@ -106,18 +106,18 @@ public static function createSymlink($symlinkTarget, $symlinkName)
public static function createMirror($symlinkTarget, $symlinkName)
{
if (strlen($symlinkTarget) == 0 || empty($symlinkTarget)) {
throw new \Exception("symlinkTarget empty!".var_export($symlinkTarget, true));
throw new \Exception('symlinkTarget empty!'.var_export($symlinkTarget, true));
}
if (strlen($symlinkName) == 0 || empty($symlinkName)) {
throw new \Exception("symlinkName empty!".var_export($symlinkName, true));
throw new \Exception('symlinkName empty!'.var_export($symlinkName, true));
}
$filesystem = new Filesystem();
$filesystem->mkdir($symlinkName);
$filesystem->mirror(
$symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget,
$symlinkName,
null,
array('copy_on_windows' => true, 'delete' => true, 'override' => true)
['copy_on_windows' => true, 'delete' => true, 'override' => true]
);
}

Expand All @@ -127,7 +127,7 @@ public static function createMirror($symlinkTarget, $symlinkName)
protected function configure()
{
$this
->setDescription("Check and if possible install symlink to ".static::$targetSuffix)
->setDescription('Check and if possible install symlink to '.static::$targetSuffix)
->addArgument('pathTo'.static::$pathName, InputArgument::OPTIONAL, 'Where is twitters/bootstrap located?')
->addArgument('pathToMopaBootstrapBundle', InputArgument::OPTIONAL, 'Where is MopaBootstrapBundle located?')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force rewrite of existing symlink if possible!')
Expand All @@ -137,7 +137,7 @@ protected function configure()
}

/**
* Get Package involved
* Get Package involved.
*
* @return string Name of twbs package
*/
Expand All @@ -154,46 +154,46 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('manual')) {
list($symlinkTarget, $symlinkName) = $this->getBootstrapPathsFromUser();
} elseif (false !== $composer = ComposerAdapter::getComposer($input, $output)) {
$targetPath = $this->getContainer()->getParameter("mopa_bootstrap.bootstrap.install_path");
$targetPath = $this->getContainer()->getParameter('mopa_bootstrap.bootstrap.install_path');
$cmanager = new ComposerPathFinder($composer);
$options = array(
$options = [
'targetSuffix' => DIRECTORY_SEPARATOR.$targetPath.static::$targetSuffix,
'sourcePrefix' => '..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR,
);
];
list($symlinkTarget, $symlinkName) = $cmanager->getSymlinkFromComposer(
self::$mopaBootstrapBundleName,
$this->getTwitterBootstrapName(),
$options
);
} else {
$this->output->writeln("<error>Could not find composer and manual option not specified!</error>");
$this->output->writeln('<error>Could not find composer and manual option not specified!</error>');

return;
}

// Automatically detect if on Win XP where symlink will allways fail
if ($input->getOption('no-symlink') || PHP_OS == "WINNT") {
$this->output->write("Checking destination");
if ($input->getOption('no-symlink') || PHP_OS == 'WINNT') {
$this->output->write('Checking destination');

if (true === self::checkSymlink($symlinkTarget, $symlinkName)) {
$this->output->writeln(" ... <comment>symlink already exists</comment>");
$this->output->writeln(' ... <comment>symlink already exists</comment>');
} else {
$this->output->writeln(" ... <comment>not existing</comment>");
$this->output->writeln(sprintf("Mirroring to: %s", $symlinkName));
$this->output->write(sprintf("from target: %s", realpath($symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget)));
$this->output->writeln(' ... <comment>not existing</comment>');
$this->output->writeln(sprintf('Mirroring to: %s', $symlinkName));
$this->output->write(sprintf('from target: %s', realpath($symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget)));
self::createMirror($symlinkTarget, $symlinkName);
}
} else {
$this->output->write("Checking symlink");
$this->output->write('Checking symlink');
if (false === self::checkSymlink($symlinkTarget, $symlinkName, true)) {
$this->output->writeln(" ... <comment>not existing</comment>");
$this->output->writeln("Creating symlink: ".$symlinkName);
$this->output->write("for target: ".$symlinkTarget);
$this->output->writeln(' ... <comment>not existing</comment>');
$this->output->writeln('Creating symlink: '.$symlinkName);
$this->output->write('for target: '.$symlinkTarget);
self::createSymlink($symlinkTarget, $symlinkName);
}
}

$this->output->writeln(" ... <info>OK</info>");
$this->output->writeln(' ... <info>OK</info>');
}

protected function getBootstrapPathsFromUser()
Expand All @@ -202,28 +202,28 @@ protected function getBootstrapPathsFromUser()
$symlinkName = $this->input->getArgument('pathToMopaBootstrapBundle');

if (empty($symlinkName)) {
throw new \Exception("pathToMopaBootstrapBundle not specified");
throw new \Exception('pathToMopaBootstrapBundle not specified');
}

if (!is_dir(dirname($symlinkName))) {
throw new \Exception("pathToMopaBootstrapBundle: ".dirname($symlinkName)." does not exist");
throw new \Exception('pathToMopaBootstrapBundle: '.dirname($symlinkName).' does not exist');
}

if (empty($symlinkTarget)) {
throw new \Exception(static::$pathName." not specified");
throw new \Exception(static::$pathName.' not specified');
}

if (substr($symlinkTarget, 0, 1) == "/") {
$this->output->writeln("<comment>Try avoiding absolute paths, for portability!</comment>");
if (substr($symlinkTarget, 0, 1) == '/') {
$this->output->writeln('<comment>Try avoiding absolute paths, for portability!</comment>');
if (!is_dir($symlinkTarget)) {
throw new \Exception("Target path ".$symlinkTarget."is not a directory!");
throw new \Exception('Target path '.$symlinkTarget.'is not a directory!');
}
} else {
$symlinkTarget = $symlinkName.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR.$symlinkTarget;
$symlinkTarget = $symlinkName.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$symlinkTarget;
}

if (!is_dir($symlinkTarget)) {
throw new \Exception(static::$pathName." would resolve to: ".$symlinkTarget."\n and this is not reachable from \npathToMopaBootstrapBundle: ".dirname($symlinkName));
throw new \Exception(static::$pathName.' would resolve to: '.$symlinkTarget."\n and this is not reachable from \npathToMopaBootstrapBundle: ".dirname($symlinkName));
}

$dialog = $this->getHelperSet()->get('dialog');
Expand All @@ -232,16 +232,16 @@ protected function getBootstrapPathsFromUser()
Pointing to: $symlinkTarget
EOF
;
$this->output->writeln(array(
$this->output->writeln([
'',
$this->getHelperSet()->get('formatter')->formatBlock($text, 'bg=blue;fg=white', true),
'',
));
]);

if ($this->input->isInteractive() && !$dialog->askConfirmation($this->output, '<question>Should this link be created? (y/n)</question>', false)) {
throw new \Exception("Aborting due to User not cofirming!");
throw new \Exception('Aborting due to User not cofirming!');
}

return array($symlinkTarget, $symlinkName);
return [$symlinkTarget, $symlinkName];
}
}
7 changes: 4 additions & 3 deletions Command/BootstrapSymlinkLessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
class BootstrapSymlinkLessCommand extends BaseBootstrapSymlinkCommand
{
public static $mopaBootstrapBundleName = "mopa/bootstrap-bundle";
public static $twitterBootstrapName = "twbs/bootstrap";
public static $mopaBootstrapBundleName = 'mopa/bootstrap-bundle';
public static $twitterBootstrapName = 'twbs/bootstrap';

protected function getTwitterBootstrapName()
{
Expand All @@ -30,7 +30,8 @@ protected function configure()

$this
->setName('mopa:bootstrap:symlink:less')
->setHelp(<<<EOT
->setHelp(
<<<EOT
The <info>mopa:bootstrap:symlink:less</info> command helps you checking and symlinking/mirroring the twitters/bootstrap library.
By default, the command uses composer to retrieve the paths of MopaBootstrapBundle and twbs/bootstrap in your vendors.
Expand Down
5 changes: 3 additions & 2 deletions Command/BootstrapSymlinkSassCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class BootstrapSymlinkSassCommand extends BaseBootstrapSymlinkCommand
{
public static $twitterBootstrapName = "twbs/bootstrap-sass";
public static $twitterBootstrapName = 'twbs/bootstrap-sass';
public static $targetSuffix = '-sass';
public static $pathName = 'TwitterBootstrapSass';

Expand All @@ -31,7 +31,8 @@ protected function configure()

$this
->setName('mopa:bootstrap:symlink:sass')
->setHelp(<<<EOT
->setHelp(
<<<EOT
The <info>mopa:bootstrap:symlink:sass</info> command helps you checking and symlinking/mirroring the twbs/bootstrap-sass library.
By default, the command uses composer to retrieve the paths of MopaBootstrapBundle and twbs/bootstrap-sass in your vendors.
Expand Down
23 changes: 12 additions & 11 deletions Command/InstallFontCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
*/
class InstallFontCommand extends ContainerAwareCommand
{
public static $iconSetsPaths = array(
"glyphicons" => "fonts/bootstrap",
"fontawesome" => "fonts/fa",
"fontawesome4" => "fonts/fa4",
"zmdi" => "fonts/zmdi",
);
public static $iconSetsPaths = [
'glyphicons' => 'fonts/bootstrap',
'fontawesome' => 'fonts/fa',
'fontawesome4' => 'fonts/fa4',
'zmdi' => 'fonts/zmdi',
];

/**
* {@inheritdoc}
Expand All @@ -38,8 +38,9 @@ protected function configure()
{
$this
->setName('mopa:bootstrap:install:font')
->setDescription("Install font to web/fonts")
->setHelp(<<<EOT
->setDescription('Install font to web/fonts')
->setHelp(
<<<EOT
The <info>mopa:bootstrap:install:font</info> command install the font configured to used into web/fonts directory
EOT
Expand All @@ -57,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$webPath = $this->getContainer()->get('kernel')->getRootDir().DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'web';

$iconWebPath = $webPath.DIRECTORY_SEPARATOR."fonts";
$iconWebPath = $webPath.DIRECTORY_SEPARATOR.'fonts';

$fs = new Filesystem();

Expand All @@ -73,15 +74,15 @@ protected function execute(InputInterface $input, OutputInterface $output)

$bsbPath = $composer->getInstallationManager()->getInstallPath($sourcePackage);

$iconSetPath = $bsbPath.DIRECTORY_SEPARATOR."Resources".DIRECTORY_SEPARATOR."public".DIRECTORY_SEPARATOR.self::$iconSetsPaths[$iconSet];
$iconSetPath = $bsbPath.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.self::$iconSetsPaths[$iconSet];

$finder->files()->in($iconSetPath);

foreach ($finder as $file) {
$fs->copy($file->getRealpath(), $iconWebPath.DIRECTORY_SEPARATOR.$file->getRelativePathname());
}

$output->writeln("Font: ".$iconSet." Installed... <info>OK</info>");
$output->writeln('Font: '.$iconSet.' Installed... <info>OK</info>');
}

public static function installFonts()
Expand Down
Loading

0 comments on commit 419bb11

Please sign in to comment.