From 85ec4e548177d51a714ff9ec9809daa34f0af1b0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 2 Jun 2017 03:27:22 +0200 Subject: [PATCH] Fix coding style --- app/config/service/service.yml | 2 +- .../Api/Client/Rebrickable/Rebrickable_v3.php | 2 ++ src/AppBundle/Api/Manager/BricksetManager.php | 3 ++- src/AppBundle/Command/InitDataCommand.php | 5 ++--- src/AppBundle/Command/LoadModelsCommand.php | 3 +-- .../Controller/DefaultController.php | 1 + src/AppBundle/Controller/ModelController.php | 4 ++-- src/AppBundle/Controller/PartController.php | 5 ++--- src/AppBundle/Controller/SearchController.php | 6 ++---- src/AppBundle/Controller/SetController.php | 5 ++--- src/AppBundle/DataFixtures/ORM/LoadColors.php | 3 +-- src/AppBundle/Entity/Rebrickable/Theme.php | 3 ++- src/AppBundle/Form/Search/SetSearchType.php | 5 +++-- src/AppBundle/Imagine/PartImageLoader.php | 5 +++-- src/AppBundle/Imagine/SetImageLoader.php | 5 +++-- src/AppBundle/Menu/Builder.php | 17 +++++++--------- src/AppBundle/Model/ModelSearch.php | 1 + src/AppBundle/Model/SetSearch.php | 1 + .../Repository/LDraw/ModelRepository.php | 3 ++- .../Repository/Rebrickable/SetRepository.php | 3 ++- .../Repository/Search/ModelRepository.php | 19 ++++++++++-------- .../Repository/Search/SetRepository.php | 19 +++++++++--------- src/AppBundle/Service/Loader/BaseLoader.php | 3 +-- src/AppBundle/Service/Loader/ModelLoader.php | 20 ++++++++----------- .../Service/Stl/StlConverterService.php | 8 ++++---- .../Service/Stl/StlRendererService.php | 4 ++-- src/AppBundle/Twig/AppExtension.php | 4 +++- src/AppBundle/Util/LDModelParser.php | 2 +- 28 files changed, 82 insertions(+), 79 deletions(-) diff --git a/app/config/service/service.yml b/app/config/service/service.yml index 26e6e9b..182db79 100644 --- a/app/config/service/service.yml +++ b/app/config/service/service.yml @@ -21,7 +21,7 @@ services: service.set: class: AppBundle\Service\SetService - arguments: ['@repository.rebrickable.inventorypart'] + arguments: ['@repository.rebrickable.inventoryPart'] service.model: class: AppBundle\Service\ModelService diff --git a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php index 24d8667..b2dfc17 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php +++ b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php @@ -38,6 +38,8 @@ class Rebrickable_v3 * @param $uri * @param array $options * + * @throws ApiException + * * @return string */ public function call($method, $uri, $options = []) diff --git a/src/AppBundle/Api/Manager/BricksetManager.php b/src/AppBundle/Api/Manager/BricksetManager.php index 4c14651..d5bbfee 100644 --- a/src/AppBundle/Api/Manager/BricksetManager.php +++ b/src/AppBundle/Api/Manager/BricksetManager.php @@ -19,7 +19,8 @@ class BricksetManager /** * BricksetManager constructor. * - * @param Brickset $bricksetClient + * @param Brickset $bricksetClient + * @param CacheProvider $cache */ public function __construct(Brickset $bricksetClient, CacheProvider $cache) { diff --git a/src/AppBundle/Command/InitDataCommand.php b/src/AppBundle/Command/InitDataCommand.php index b5a96f9..abe555d 100644 --- a/src/AppBundle/Command/InitDataCommand.php +++ b/src/AppBundle/Command/InitDataCommand.php @@ -4,7 +4,6 @@ namespace AppBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -20,7 +19,7 @@ class InitDataCommand extends ContainerAwareCommand ->setHelp('This command allows you to load initial data of models and sets into aplication') ->setDefinition( new InputDefinition([ - new InputOption('ldraw', 'l',InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'), + new InputOption('ldraw', 'l', InputOption::VALUE_OPTIONAL, 'Path to LDraw library directory'), ]) ); } @@ -34,7 +33,7 @@ class InitDataCommand extends ContainerAwareCommand '--all' => true, ]; - if($ldraw = $input->getOption('ldraw')) { + if ($ldraw = $input->getOption('ldraw')) { $loadModelsInput['--ldraw'] = $ldraw; } diff --git a/src/AppBundle/Command/LoadModelsCommand.php b/src/AppBundle/Command/LoadModelsCommand.php index b806640..3649ce4 100644 --- a/src/AppBundle/Command/LoadModelsCommand.php +++ b/src/AppBundle/Command/LoadModelsCommand.php @@ -5,7 +5,6 @@ namespace AppBundle\Command; use AppBundle\Service\Loader\ModelLoader; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Command\LockableTrait; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -50,7 +49,7 @@ class LoadModelsCommand extends ContainerAwareCommand return 1; } - if($ldraw = $input->getOption('ldraw')) { + if ($ldraw = $input->getOption('ldraw')) { $modelLoader->setLDrawLibraryContext(realpath($ldraw)); } else { $ldraw = $modelLoader->downloadLibrary($this->getContainer()->getParameter('app.ld_library_download_url')); diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index 576b743..06af351 100644 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -20,6 +20,7 @@ class DefaultController extends Controller /** @var SetRepository $setRepository */ $setRepository = $this->get('repository.rebrickable.set'); + return $this->render('default/index.html.twig', [ 'models' => $modelRepository->count(), 'sets' => $setRepository->count(), diff --git a/src/AppBundle/Controller/ModelController.php b/src/AppBundle/Controller/ModelController.php index 5cd0213..1c8783f 100644 --- a/src/AppBundle/Controller/ModelController.php +++ b/src/AppBundle/Controller/ModelController.php @@ -33,7 +33,7 @@ class ModelController extends Controller $form->handleRequest($request); $elasticaManager = $this->get('fos_elastica.manager'); - $results = $elasticaManager->getRepository(Model::class)->search($modelSearch,5000); + $results = $elasticaManager->getRepository(Model::class)->search($modelSearch, 5000); /** @var Paginator $paginator */ $paginator = $this->get('knp_paginator'); @@ -94,7 +94,7 @@ class ModelController extends Controller $response->headers->set('Content-Type', 'application/zip'); // escape forbidden characters from filename - $filename = preg_replace('/[^a-z0-9\.]/i', '_',"model_{$model->getId()}_{$model->getName()}.zip"); + $filename = preg_replace('/[^a-z0-9\.]/i', '_', "model_{$model->getId()}_{$model->getName()}.zip"); // Create the disposition of the file $disposition = $response->headers->makeDisposition( diff --git a/src/AppBundle/Controller/PartController.php b/src/AppBundle/Controller/PartController.php index 1a9e142..0c92d71 100644 --- a/src/AppBundle/Controller/PartController.php +++ b/src/AppBundle/Controller/PartController.php @@ -4,7 +4,6 @@ namespace AppBundle\Controller; use AppBundle\Api\Exception\EmptyResponseException; use AppBundle\Entity\Rebrickable\Part; -use AppBundle\Entity\Rebrickable\Set; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -24,8 +23,8 @@ class PartController extends Controller { $apiPart = null; if ($part) { - if($model = $part->getModel()) { - $this->redirectToRoute('model_detail',['id' => $model->getId()]); + if ($model = $part->getModel()) { + $this->redirectToRoute('model_detail', ['id' => $model->getId()]); } try { diff --git a/src/AppBundle/Controller/SearchController.php b/src/AppBundle/Controller/SearchController.php index 7181b62..a6b0edd 100644 --- a/src/AppBundle/Controller/SearchController.php +++ b/src/AppBundle/Controller/SearchController.php @@ -9,9 +9,7 @@ use AppBundle\Model\SetSearch; use AppBundle\Repository\Search\ModelRepository; use AppBundle\Repository\Search\SetRepository; use FOS\ElasticaBundle\HybridResult; -use FOS\ElasticaBundle\Repository; use Liip\ImagineBundle\Imagine\Cache\CacheManager; -use Liip\ImagineBundle\Imagine\Cache\Resolver\CacheResolver; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; @@ -81,7 +79,7 @@ class SearchController extends Controller 'id' => $id, 'name' => $name, 'url' => $this->generateUrl('model_detail', ['id' => $model->getTransformed()->getId()]), - 'img' => $liip->getBrowserPath('-1/'.$model->getTransformed()->getId().'.png','part_min'), + 'img' => $liip->getBrowserPath('-1/'.$model->getTransformed()->getId().'.png', 'part_min'), ]; } @@ -95,7 +93,7 @@ class SearchController extends Controller 'id' => $id, 'name' => $name, 'url' => $this->generateUrl('set_detail', ['id' => $set->getTransformed()->getId()]), - 'img' => $liip->getBrowserPath($set->getTransformed()->getId().'.jpg','set_min'), + 'img' => $liip->getBrowserPath($set->getTransformed()->getId().'.jpg', 'set_min'), ]; } diff --git a/src/AppBundle/Controller/SetController.php b/src/AppBundle/Controller/SetController.php index bdbadd8..8714b1c 100644 --- a/src/AppBundle/Controller/SetController.php +++ b/src/AppBundle/Controller/SetController.php @@ -34,7 +34,7 @@ class SetController extends Controller /** @var SetRepository $setRepository */ $setRepository = $this->get('fos_elastica.manager')->getRepository(Set::class); - $results = $setRepository->search($setSearch,5000); + $results = $setRepository->search($setSearch, 5000); $paginator = $this->get('knp_paginator'); $sets = $paginator->paginate( @@ -90,7 +90,6 @@ class SetController extends Controller $setService = $this->get('service.set'); $inventoryPartRepository = $this->get('repository.rebrickable.inventoryPart'); - $models = $setService->getModels($set, false); $missing = $setService->getParts($set, false, false); $missingCount = $inventoryPartRepository->getPartCount($set, false, false); @@ -163,7 +162,7 @@ class SetController extends Controller try { $colors = $setService->getModelsGroupedByColor($set, false); - $missing = $setService->getParts($set,false,false); + $missing = $setService->getParts($set, false, false); } catch (\Exception $e) { $this->addFlash('error', $e->getMessage()); } diff --git a/src/AppBundle/DataFixtures/ORM/LoadColors.php b/src/AppBundle/DataFixtures/ORM/LoadColors.php index e778c88..9956e27 100644 --- a/src/AppBundle/DataFixtures/ORM/LoadColors.php +++ b/src/AppBundle/DataFixtures/ORM/LoadColors.php @@ -2,7 +2,6 @@ namespace AppBundle\DataFixtures\ORM; - use AppBundle\Entity\Color; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; @@ -43,4 +42,4 @@ class LoadColors implements FixtureInterface, ContainerAwareInterface $manager->flush(); } -} \ No newline at end of file +} diff --git a/src/AppBundle/Entity/Rebrickable/Theme.php b/src/AppBundle/Entity/Rebrickable/Theme.php index 8b95fa5..6f0626f 100644 --- a/src/AppBundle/Entity/Rebrickable/Theme.php +++ b/src/AppBundle/Entity/Rebrickable/Theme.php @@ -81,7 +81,8 @@ class Theme return $this; } - public function getFullName() { + public function getFullName() + { $theme = $this; $name = []; diff --git a/src/AppBundle/Form/Search/SetSearchType.php b/src/AppBundle/Form/Search/SetSearchType.php index f6ebcdb..6d18117 100644 --- a/src/AppBundle/Form/Search/SetSearchType.php +++ b/src/AppBundle/Form/Search/SetSearchType.php @@ -60,8 +60,9 @@ class SetSearchType extends AbstractType 'choices' => $this->themeRepository->findAll(), 'choice_label' => 'fullName', 'choice_translation_domain' => false, - 'group_by' => function($theme, $key, $index) { + 'group_by' => function ($theme, $key, $index) { $parent = $theme->getParent(); + return $parent ? $parent->getParent() ? $parent->getParent()->getName() : $parent->getName() : $theme->getName(); }, 'choice_value' => 'id', @@ -79,7 +80,7 @@ class SetSearchType extends AbstractType $resolver->setDefaults([ 'csrf_protection' => false, 'data_class' => SetSearch::class, - 'method' => 'GET' + 'method' => 'GET', ]); } diff --git a/src/AppBundle/Imagine/PartImageLoader.php b/src/AppBundle/Imagine/PartImageLoader.php index 2b7a126..0bbb32b 100644 --- a/src/AppBundle/Imagine/PartImageLoader.php +++ b/src/AppBundle/Imagine/PartImageLoader.php @@ -38,8 +38,9 @@ class PartImageLoader extends BaseImageLoader // try to load image from rebrickable website try { if ($this->remoteFileExists($this->rebrickableContext.$path)) { - $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n'))); - return file_get_contents($this->rebrickableContext.strtolower($path),false,$context); + $context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]); + + return file_get_contents($this->rebrickableContext.strtolower($path), false, $context); } } catch (\Exception $e) { throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e); diff --git a/src/AppBundle/Imagine/SetImageLoader.php b/src/AppBundle/Imagine/SetImageLoader.php index 797fa5a..b7c557d 100644 --- a/src/AppBundle/Imagine/SetImageLoader.php +++ b/src/AppBundle/Imagine/SetImageLoader.php @@ -32,8 +32,9 @@ class SetImageLoader extends BaseImageLoader // try to load image from rebrickable website try { if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) { - $context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n'))); - return file_get_contents($this->rebrickableContext.strtolower($path),false,$context); + $context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]); + + return file_get_contents($this->rebrickableContext.strtolower($path), false, $context); } } catch (\Exception $e) { throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e); diff --git a/src/AppBundle/Menu/Builder.php b/src/AppBundle/Menu/Builder.php index 35bda4a..c5de5f0 100644 --- a/src/AppBundle/Menu/Builder.php +++ b/src/AppBundle/Menu/Builder.php @@ -3,7 +3,6 @@ namespace AppBundle\Menu; use Knp\Menu\FactoryInterface; -use Knp\Menu\ItemInterface; use Symfony\Component\HttpFoundation\RequestStack; class Builder @@ -26,7 +25,6 @@ class Builder $this->requestStack = $requestStack; } - public function mainMenu(array $options) { $request = $this->requestStack->getCurrentRequest(); @@ -37,7 +35,7 @@ class Builder ], ]); - $models = $menu->addChild( 'page.model.index', [ + $models = $menu->addChild('page.model.index', [ 'route' => 'model_index', ]); @@ -46,7 +44,7 @@ class Builder 'routeParameters' => ['id' => $request->get('id', 0)], 'display' => false, 'extras' => [ - 'value' => $request->get('id', 0) + 'value' => $request->get('id', 0), ], ]); @@ -54,7 +52,7 @@ class Builder 'route' => 'set_index', 'options' => [ // 'icon' => 'edit', - ] + ], ]); $sets->addChild('page.set.detail', [ @@ -62,7 +60,7 @@ class Builder 'routeParameters' => ['id' => $request->get('id', 0)], 'display' => false, 'extras' => [ - 'value' => $request->get('id', 0) + 'value' => $request->get('id', 0), ], ]); @@ -70,7 +68,7 @@ class Builder 'route' => 'search_results', 'display' => false, 'extras' => [ - 'value' => $request->get('query', 0) + 'value' => $request->get('query', 0), ], ]); @@ -83,7 +81,7 @@ class Builder 'display' => false, 'options' => [ // 'icon' => 'edit', - ] + ], ]); $parts->addChild('page.part.detail', [ @@ -91,11 +89,10 @@ class Builder 'routeParameters' => ['id' => $request->get('id', 0)], 'display' => false, 'extras' => [ - 'value' => $request->get('id', 0) + 'value' => $request->get('id', 0), ], ]); - return $menu; } } diff --git a/src/AppBundle/Model/ModelSearch.php b/src/AppBundle/Model/ModelSearch.php index ea1b6fb..123a245 100644 --- a/src/AppBundle/Model/ModelSearch.php +++ b/src/AppBundle/Model/ModelSearch.php @@ -14,6 +14,7 @@ class ModelSearch /** * ModelSearch constructor. + * * @param string $query */ public function __construct($query = '') diff --git a/src/AppBundle/Model/SetSearch.php b/src/AppBundle/Model/SetSearch.php index ff46644..6c5acec 100644 --- a/src/AppBundle/Model/SetSearch.php +++ b/src/AppBundle/Model/SetSearch.php @@ -20,6 +20,7 @@ class SetSearch /** * SetSearch constructor. + * * @param string $query */ public function __construct($query = '') diff --git a/src/AppBundle/Repository/LDraw/ModelRepository.php b/src/AppBundle/Repository/LDraw/ModelRepository.php index 05c7fce..42cdebf 100644 --- a/src/AppBundle/Repository/LDraw/ModelRepository.php +++ b/src/AppBundle/Repository/LDraw/ModelRepository.php @@ -106,7 +106,8 @@ class ModelRepository extends BaseRepository return $queryBuilder->getQuery()->getResult(); } - public function count() { + public function count() + { $queryBuilder = $this->createQueryBuilder('model'); $queryBuilder->select('count(model)'); diff --git a/src/AppBundle/Repository/Rebrickable/SetRepository.php b/src/AppBundle/Repository/Rebrickable/SetRepository.php index 9674dc7..feadbd6 100644 --- a/src/AppBundle/Repository/Rebrickable/SetRepository.php +++ b/src/AppBundle/Repository/Rebrickable/SetRepository.php @@ -73,7 +73,8 @@ class SetRepository extends BaseRepository return $queryBuilder->getQuery()->getSingleScalarResult(); } - public function count() { + public function count() + { $queryBuilder = $this->createQueryBuilder('s'); $queryBuilder->select('count(s)'); diff --git a/src/AppBundle/Repository/Search/ModelRepository.php b/src/AppBundle/Repository/Search/ModelRepository.php index c948ef2..6c9d146 100644 --- a/src/AppBundle/Repository/Search/ModelRepository.php +++ b/src/AppBundle/Repository/Search/ModelRepository.php @@ -10,9 +10,11 @@ class ModelRepository extends Repository { /** * @param ModelSearch $modelSearch + * * @return \Elastica\Query */ - public function getSearchQuery(ModelSearch $modelSearch) { + public function getSearchQuery(ModelSearch $modelSearch) + { $boolQuery = new Query\BoolQuery(); if ($searchQuery = $modelSearch->getQuery()) { @@ -23,7 +25,6 @@ class ModelRepository extends Repository $query->setFuzziness(0.7); $query->setMinimumShouldMatch('80%'); $query->setOperator('and'); - } else { $query = new Query\MatchAll(); } @@ -41,11 +42,13 @@ class ModelRepository extends Repository public function search(ModelSearch $modelSearch, $limit = 500) { - $query = $this->getSearchQuery($modelSearch); + $query = $this->getSearchQuery($modelSearch); + return $this->find($query, $limit); } - public function findHighlighted($query, $limit = 500) { + public function findHighlighted($query, $limit = 500) + { $modelSearch = new ModelSearch(); $modelSearch->setQuery($query); @@ -55,10 +58,10 @@ class ModelRepository extends Repository $query->setHighlight([ 'pre_tags' => [''], 'post_tags' => [''], - "fields" => [ - "name" => new \stdClass(), - "id" => new \stdClass() - ] + 'fields' => [ + 'name' => new \stdClass(), + 'id' => new \stdClass(), + ], ]); return $this->findHybrid($query, $limit); diff --git a/src/AppBundle/Repository/Search/SetRepository.php b/src/AppBundle/Repository/Search/SetRepository.php index cf126c8..226dbde 100644 --- a/src/AppBundle/Repository/Search/SetRepository.php +++ b/src/AppBundle/Repository/Search/SetRepository.php @@ -6,18 +6,18 @@ use AppBundle\Model\SetSearch; use Elastica\Query; use Elastica\Query\BoolQuery; use Elastica\Query\Match; -use Elastica\Query\MultiMatch; use Elastica\Query\Range; -use Elastica\Query\Wildcard; use FOS\ElasticaBundle\Repository; class SetRepository extends Repository { /** * @param SetSearch $setSearch + * * @return Query */ - public function getSearchQuery(SetSearch $setSearch) { + public function getSearchQuery(SetSearch $setSearch) + { $boolQuery = new BoolQuery(); if ($searchQuery = $setSearch->getQuery()) { @@ -28,7 +28,7 @@ class SetRepository extends Repository $query->setFuzziness(0.7); $query->setMinimumShouldMatch('80%'); $query->setOperator('and'); - + $boolQuery->addMust($query); } else { $query = new \Elastica\Query\MatchAll(); @@ -69,7 +69,8 @@ class SetRepository extends Repository return $this->find($query, $limit); } - public function findHighlighted($query, $limit = 500) { + public function findHighlighted($query, $limit = 500) + { $setSearch = new SetSearch(); $setSearch->setQuery($query); @@ -79,10 +80,10 @@ class SetRepository extends Repository $query->setHighlight([ 'pre_tags' => [''], 'post_tags' => [''], - "fields" => [ - "name" => new \stdClass(), - "id" => new \stdClass() - ] + 'fields' => [ + 'name' => new \stdClass(), + 'id' => new \stdClass(), + ], ]); return $this->findHybrid($query, $limit); diff --git a/src/AppBundle/Service/Loader/BaseLoader.php b/src/AppBundle/Service/Loader/BaseLoader.php index f915516..8444e07 100644 --- a/src/AppBundle/Service/Loader/BaseLoader.php +++ b/src/AppBundle/Service/Loader/BaseLoader.php @@ -10,7 +10,6 @@ use Monolog\Logger; use Symfony\Bundle\FrameworkBundle\Translation\Translator; use Symfony\Component\Asset\Exception\LogicException; use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Debug\Exception\ContextErrorException; @@ -45,7 +44,7 @@ abstract class BaseLoader * Loader constructor. * * @param EntityManager $em - * @param Logger $logger + * @param Logger $logger * @param Translator $formatTransformer */ public function setArguments(EntityManager $em, $logger, $formatTransformer) diff --git a/src/AppBundle/Service/Loader/ModelLoader.php b/src/AppBundle/Service/Loader/ModelLoader.php index c4466ba..04c3ca6 100644 --- a/src/AppBundle/Service/Loader/ModelLoader.php +++ b/src/AppBundle/Service/Loader/ModelLoader.php @@ -19,8 +19,6 @@ use AppBundle\Util\RelationMapper; use League\Flysystem\Adapter\Local; use League\Flysystem\Exception; use League\Flysystem\Filesystem; -use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; class ModelLoader extends BaseLoader { @@ -116,13 +114,13 @@ class ModelLoader extends BaseLoader } /** - * Load one model into database + * Load one model into database. * * @param string $file Absolute filepath of model to load */ public function loadOne($file) { - if(!$this->ldrawLibraryContext) { + if (!$this->ldrawLibraryContext) { throw new MissingContextException('LDrawLibrary'); } @@ -140,13 +138,12 @@ class ModelLoader extends BaseLoader } } - /** - * Load all models from ldraw library context into database + * Load all models from ldraw library context into database. */ public function loadAll() { - if(!$this->ldrawLibraryContext) { + if (!$this->ldrawLibraryContext) { throw new MissingContextException('LDrawLibrary'); } @@ -162,7 +159,7 @@ class ModelLoader extends BaseLoader foreach ($files as $file) { $this->progressBar->setMessage($file['basename']); - if($file['type'] == 'file' && $file['extension'] == 'dat') { + if ($file['type'] == 'file' && $file['extension'] == 'dat') { $connection = $this->em->getConnection(); $connection->beginTransaction(); @@ -217,7 +214,7 @@ class ModelLoader extends BaseLoader if (($parentId = $this->getParentId($modelArray)) && ($parentModelFile = $this->findSubmodelFile($parentId)) !== null) { if ($parentModel = $this->loadModel($parentModelFile)) { // Remove old model if ~moved to - if($this->rewrite && ($old = $modelRepository->find($modelArray['id'])) != null) { + if ($this->rewrite && ($old = $modelRepository->find($modelArray['id'])) != null) { $modelRepository->delete($old); } @@ -331,8 +328,7 @@ class ModelLoader extends BaseLoader // Try to find model in current file's directory if ($this->fileContext && $this->fileContext->has($filename)) { return $this->fileContext->getAdapter()->getPathPrefix().$filename; - } - elseif ($this->ldrawLibraryContext) { + } elseif ($this->ldrawLibraryContext) { // Try to find model in current LDRAW\PARTS sub-directory if ($this->ldrawLibraryContext->has('parts'.DIRECTORY_SEPARATOR.$filename)) { return $this->ldrawLibraryContext->getAdapter()->getPathPrefix().'parts'.DIRECTORY_SEPARATOR.$filename; @@ -357,7 +353,7 @@ class ModelLoader extends BaseLoader { try { $adapter = new Local(dirname($file)); - $this->fileContext = new Filesystem($adapter); + $this->fileContext = new Filesystem($adapter); } catch (Exception $exception) { $this->logger->error($exception->getMessage()); diff --git a/src/AppBundle/Service/Stl/StlConverterService.php b/src/AppBundle/Service/Stl/StlConverterService.php index 26c0fd5..4af66e0 100644 --- a/src/AppBundle/Service/Stl/StlConverterService.php +++ b/src/AppBundle/Service/Stl/StlConverterService.php @@ -35,9 +35,9 @@ class StlConverterService /** * StlConverterService constructor. * - * @param string $ldview Path to LDView OSMesa binary file + * @param string $ldview Path to LDView OSMesa binary file * @param FilesystemInterface $mediaFilesystem Filesystem for generated web assets - * @param StlFixerService $stlFixer + * @param StlFixerService $stlFixer */ public function __construct($ldview, $mediaFilesystem, $stlFixer) { @@ -59,7 +59,7 @@ class StlConverterService * stores created file to $stlStorage filesystem. * * @param string $file - * @param bool $rewrite + * @param bool $rewrite * * @throws ConvertingFailedException * @@ -104,7 +104,7 @@ class StlConverterService * stores created file to $stlStorage filesystem. * * @param string $file - * @param bool $rewrite + * @param bool $rewrite * * @throws ConvertingFailedException * diff --git a/src/AppBundle/Service/Stl/StlRendererService.php b/src/AppBundle/Service/Stl/StlRendererService.php index fcf0b6d..301385a 100644 --- a/src/AppBundle/Service/Stl/StlRendererService.php +++ b/src/AppBundle/Service/Stl/StlRendererService.php @@ -160,7 +160,7 @@ class StlRendererService * http://www.povray.org/ * * @param string $file The full path to .pov file to be rendered - * @param string $to Destination directory path + * @param string $to Destination directory path * * @throws RenderFailedException throws exception if there are problems rendering image * @throws FileNotFoundException throws exception if source file not found @@ -173,7 +173,7 @@ class StlRendererService throw new FileNotFoundException($file); } - if(!file_exists($to)) { + if (!file_exists($to)) { mkdir($to); } diff --git a/src/AppBundle/Twig/AppExtension.php b/src/AppBundle/Twig/AppExtension.php index f46e7db..c5a6eab 100644 --- a/src/AppBundle/Twig/AppExtension.php +++ b/src/AppBundle/Twig/AppExtension.php @@ -73,12 +73,14 @@ class AppExtension extends \Twig_Extension return $size; } - public function fileTimestamp($filePath) { + public function fileTimestamp($filePath) + { $changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath); if (!$changeDate) { //Fallback if mtime could not be found: $changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y')); } + return $filePath.'?'.$changeDate; } diff --git a/src/AppBundle/Util/LDModelParser.php b/src/AppBundle/Util/LDModelParser.php index 30f4c92..6911042 100644 --- a/src/AppBundle/Util/LDModelParser.php +++ b/src/AppBundle/Util/LDModelParser.php @@ -71,7 +71,7 @@ class LDModelParser $keywords = explode(',', preg_replace('/^!KEYWORDS /', '', $line)); foreach ($keywords as $keyword) { $keyword = trim($keyword); - if ($keyword && !in_array($keyword,$model['keywords'])) { + if ($keyword && !in_array($keyword, $model['keywords'])) { $model['keywords'][] = $keyword; } }