Applied symplify rules to codebase.

This commit is contained in:
Jan Böhmer 2020-01-05 22:49:00 +01:00
parent 2f20d90041
commit 388e847b17
136 changed files with 1370 additions and 789 deletions

View file

@ -27,6 +27,9 @@ namespace App\Command;
use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentReverseSearch;
use function count;
use const DIRECTORY_SEPARATOR;
use IntlDateFormatter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
@ -83,11 +86,11 @@ class CleanAttachmentsCommand extends Command
$table = new Table($output);
$table->setHeaders(['Filename', 'MIME Type', 'Last modified date']);
$dateformatter = \IntlDateFormatter::create(null, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
$dateformatter = IntlDateFormatter::create(null, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
foreach ($finder as $file) {
//If not attachment object uses this file, print it
if (0 === \count($this->reverseSearch->findAttachmentsByFile($file))) {
if (0 === count($this->reverseSearch->findAttachmentsByFile($file))) {
$file_list[] = $file;
$table->addRow([
$fs->makePathRelative($file->getPathname(), $mediaPath),
@ -97,10 +100,10 @@ class CleanAttachmentsCommand extends Command
}
}
if (\count($file_list) > 0) {
if (count($file_list) > 0) {
$table->render();
$continue = $io->confirm(sprintf('Found %d abandoned files. Do you want to delete them? This can not be undone!', \count($file_list)), false);
$continue = $io->confirm(sprintf('Found %d abandoned files. Do you want to delete them? This can not be undone!', count($file_list)), false);
if (! $continue) {
//We are finished here, when no files should be deleted
@ -128,7 +131,7 @@ class CleanAttachmentsCommand extends Command
protected function removeEmptySubFolders($path)
{
$empty = true;
foreach (glob($path.\DIRECTORY_SEPARATOR.'*') as $file) {
foreach (glob($path.DIRECTORY_SEPARATOR.'*') as $file) {
$empty &= is_dir($file) && $this->removeEmptySubFolders($file);
}

View file

@ -36,6 +36,7 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
use App\Helpers\BBCodeToMarkdownConverter;
use function count;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Console\Command\Command;
@ -49,9 +50,13 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
*/
class ConvertBBCodeCommand extends Command
{
/** @var string The LIKE criteria used to detect on SQL server if a entry contains BBCode */
/**
* @var string The LIKE criteria used to detect on SQL server if a entry contains BBCode
*/
protected const BBCODE_CRITERIA = '%[%]%[/%]%';
/** @var string The regex (performed in PHP) used to check if a property really contains BBCODE */
/**
* @var string The regex (performed in PHP) used to check if a property really contains BBCODE
*/
protected const BBCODE_REGEX = '/\\[.+\\].*\\[\\/.+\\]/';
protected static $defaultName = 'app:convert-bbcode';
@ -125,7 +130,7 @@ class ConvertBBCodeCommand extends Command
//Fetch resulting classes
$results = $qb->getQuery()->getResult();
$io->note(sprintf('Found %d entities, that need to be converted!', \count($results)));
$io->note(sprintf('Found %d entities, that need to be converted!', count($results)));
//In verbose mode print the names of the entities
foreach ($results as $result) {

View file

@ -25,7 +25,10 @@ declare(strict_types=1);
namespace App\Command;
use App\Entity\PriceInformations\Currency;
use function count;
use Doctrine\ORM\EntityManagerInterface;
use Exchanger\Exception\Exception;
use function strlen;
use Swap\Builder;
use Swap\Swap;
use Symfony\Component\Console\Command\Command;
@ -70,7 +73,7 @@ class UpdateExchangeRatesCommand extends Command
$io = new SymfonyStyle($input, $output);
//Check for valid base current
if (3 !== \strlen($this->base_current)) {
if (3 !== strlen($this->base_current)) {
$io->error('Choosen Base current is not valid. Check your settings!');
return;
@ -108,15 +111,15 @@ class UpdateExchangeRatesCommand extends Command
$this->em->persist($currency);
++$success_counter;
} catch (\Exchanger\Exception\Exception $ex) {
} catch (Exception $exception) {
$io->warning(sprintf('Error updating %s:', $currency->getIsoCode()));
$io->warning($ex->getMessage());
$io->warning($exception->getMessage());
}
}
//Save to database
$this->em->flush();
$io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, \count($candidates)));
$io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, count($candidates)));
}
}