From 30c4eb8c824d52c3a7fdfbda07ca455bc25e1507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=BCbner?= Date: Sun, 16 Apr 2017 22:12:58 +0200 Subject: [PATCH] Fix coding style --- .../Api/Client/Brickset/Brickset.php | 4 +- .../Api/Client/Rebrickable/Rebrickable_v3.php | 5 +- src/AppBundle/Api/Manager/BricksetManager.php | 9 ++-- .../Api/Manager/RebrickableManager.php | 9 ++-- src/AppBundle/Controller/MediaController.php | 2 - src/AppBundle/Controller/ModelController.php | 8 ++-- .../Rebrickable/ColorController.php | 8 ++-- .../Controller/Rebrickable/SetController.php | 13 +++-- src/AppBundle/Controller/SetController.php | 48 ++----------------- .../Entity/Rebrickable/Inventory.php | 1 - .../Exception/ConvertingFailedException.php | 11 ++--- .../Rebrickable/InventoryRepository.php | 6 +-- .../Rebrickable/Inventory_PartRepository.php | 5 +- .../Rebrickable/Inventory_SetRepository.php | 11 ++--- .../Repository/Rebrickable/SetRepository.php | 7 ++- .../Rebrickable/ThemeRepository.php | 8 ++-- src/AppBundle/Twig/AppExtension.php | 23 ++++----- 17 files changed, 65 insertions(+), 113 deletions(-) diff --git a/src/AppBundle/Api/Client/Brickset/Brickset.php b/src/AppBundle/Api/Client/Brickset/Brickset.php index ace0d9c..62397f0 100644 --- a/src/AppBundle/Api/Client/Brickset/Brickset.php +++ b/src/AppBundle/Api/Client/Brickset/Brickset.php @@ -13,7 +13,6 @@ use AppBundle\Api\Exception\ApiException; use AppBundle\Api\Exception\AuthenticationFailedException; use AppBundle\Api\Exception\CallFailedException; use AppBundle\Api\Exception\EmptyResponseException; -use Symfony\Component\Asset\Exception\LogicException; use Symfony\Component\Debug\Exception\ContextErrorException; class Brickset extends \SoapClient @@ -79,6 +78,7 @@ class Brickset extends \SoapClient try { $this->checkApiKey(); + return $this->__soapCall($method, [$parameters])->{$method.'Result'}; } catch (\SoapFault $e) { throw new CallFailedException(ApiException::BRICKSET); @@ -266,7 +266,7 @@ class Brickset extends \SoapClient { $parameters['apiKey'] = $this->apiKey; - if($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') { + if ($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') { throw new AuthenticationFailedException(ApiException::BRICKSET); } } diff --git a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php index 97fa006..24d8667 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php +++ b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php @@ -9,7 +9,6 @@ use AppBundle\Api\Exception\EmptyResponseException; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ConnectException; -use Symfony\Component\Asset\Exception\LogicException; class Rebrickable_v3 { @@ -59,11 +58,11 @@ class Rebrickable_v3 } catch (ClientException $e) { if ($e->getCode() == 404) { throw new EmptyResponseException(ApiException::REBRICKABLE); - } else if ($e->getCode() == 401) { + } elseif ($e->getCode() == 401) { throw new AuthenticationFailedException(ApiException::REBRICKABLE); } - throw new ApiException(ApiException::REBRICKABLE,$e,$e->getCode()); + throw new ApiException(ApiException::REBRICKABLE, $e, $e->getCode()); } } } diff --git a/src/AppBundle/Api/Manager/BricksetManager.php b/src/AppBundle/Api/Manager/BricksetManager.php index c9ebd71..805eaa7 100644 --- a/src/AppBundle/Api/Manager/BricksetManager.php +++ b/src/AppBundle/Api/Manager/BricksetManager.php @@ -48,15 +48,18 @@ class BricksetManager return isset($sets[0]) ? $sets[0] : null; } - public function getSetInstructions($id) { + public function getSetInstructions($id) + { return $this->bricksetClient->getInstructions($id); } - public function getSetReviews($id) { + public function getSetReviews($id) + { return $this->bricksetClient->getReviews($id); } - public function getAdditionalImages($id) { + public function getAdditionalImages($id) + { return $this->bricksetClient->getAdditionalImages($id); } } diff --git a/src/AppBundle/Api/Manager/RebrickableManager.php b/src/AppBundle/Api/Manager/RebrickableManager.php index 8fc528f..622e020 100644 --- a/src/AppBundle/Api/Manager/RebrickableManager.php +++ b/src/AppBundle/Api/Manager/RebrickableManager.php @@ -119,18 +119,19 @@ class RebrickableManager return $this->serializer->deserialize($data, PartCategory::class, self::FORMAT); } - public function getPartsByLDrawNumber($number) { + public function getPartsByLDrawNumber($number) + { $options = [ 'query' => [ - 'ldraw_id' => $number + 'ldraw_id' => $number, ], ]; - $response = $this->rebrickableClient->call('GET','lego/parts', $options); + $response = $this->rebrickableClient->call('GET', 'lego/parts', $options); $data = json_decode($response, true)['results']; - return $this->serializer->denormalize($data,Part::class.'[]',self::FORMAT); + return $this->serializer->denormalize($data, Part::class.'[]', self::FORMAT); } /** diff --git a/src/AppBundle/Controller/MediaController.php b/src/AppBundle/Controller/MediaController.php index e9e4b23..8ec06c8 100644 --- a/src/AppBundle/Controller/MediaController.php +++ b/src/AppBundle/Controller/MediaController.php @@ -2,13 +2,11 @@ namespace AppBundle\Controller; -use AppBundle\Entity\LDraw\Model; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; -use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\Routing\Annotation\Route; /** diff --git a/src/AppBundle/Controller/ModelController.php b/src/AppBundle/Controller/ModelController.php index 92ce1d3..329cd68 100644 --- a/src/AppBundle/Controller/ModelController.php +++ b/src/AppBundle/Controller/ModelController.php @@ -28,8 +28,7 @@ class ModelController extends Controller { $form = $this->get('form.factory')->create(ModelFilterType::class); - $filterBuilder = $this->get('repository.ldraw.model') - ->createQueryBuilder('model'); + $filterBuilder = $this->get('repository.ldraw.model')->getFilteredQueryBuilder(); if ($request->query->has($form->getName())) { // manually bind values from the request @@ -62,7 +61,7 @@ class ModelController extends Controller { $em = $this->getDoctrine()->getManager(); - if($model = $this->get('manager.ldraw.model')->findByNumber($number)) { + if ($model = $this->get('repository.ldraw.model')->findOneByNumber($number)) { try { $rbParts = $model != null ? $em->getRepository(Part::class)->findAllByModel($model) : null; $sets = $model != null ? $em->getRepository(Set::class)->findAllByModel($model) : null; @@ -73,12 +72,11 @@ class ModelController extends Controller 'model' => $model, 'rbParts' => $rbParts, 'sets' => $sets, - 'related' => $related + 'related' => $related, ]); } catch (\Exception $e) { $this->addFlash('error', $e->getMessage()); } - } return $this->render('error/error.html.twig'); diff --git a/src/AppBundle/Controller/Rebrickable/ColorController.php b/src/AppBundle/Controller/Rebrickable/ColorController.php index 6b0b8ad..518f862 100644 --- a/src/AppBundle/Controller/Rebrickable/ColorController.php +++ b/src/AppBundle/Controller/Rebrickable/ColorController.php @@ -3,8 +3,8 @@ namespace AppBundle\Controller\Rebrickable; use AppBundle\Entity\Rebrickable\Color; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; /** * Part controller. @@ -14,10 +14,10 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class ColorController extends Controller { /** - * * @Route("/", name="color_index") */ - public function indexAction() { + public function indexAction() + { $em = $this->getDoctrine()->getManager(); $colors = $em->getRepository(Color::class)->findAll(); @@ -26,4 +26,4 @@ class ColorController extends Controller 'colors' => $colors, ]); } -} \ No newline at end of file +} diff --git a/src/AppBundle/Controller/Rebrickable/SetController.php b/src/AppBundle/Controller/Rebrickable/SetController.php index 485b543..04f74df 100644 --- a/src/AppBundle/Controller/Rebrickable/SetController.php +++ b/src/AppBundle/Controller/Rebrickable/SetController.php @@ -2,18 +2,13 @@ namespace AppBundle\Controller\Rebrickable; -use AppBundle\Api\Exception\EmptyResponseException; -use AppBundle\Entity\LDraw\Model; use AppBundle\Entity\Rebrickable\Color; use AppBundle\Entity\Rebrickable\Inventory_Part; use AppBundle\Entity\Rebrickable\Inventory_Set; use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Set; -use AppBundle\Entity\Rebrickable\Theme; -use AppBundle\Form\FilterSetType; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; /** @@ -24,7 +19,8 @@ class SetController extends Controller /** * @Route("/{number}/parts", name="rebrickable_set_parts") */ - public function partsAction(Set $set) { + public function partsAction(Set $set) + { $em = $this->getDoctrine()->getManager(); $em->getRepository(Color::class)->findAll(); @@ -41,13 +37,15 @@ class SetController extends Controller $json = json_encode($template->getContent()); $response = new Response($json, 200); $response->headers->set('Content-Type', 'application/json'); + return $response; } /** * @Route("/{number}/sets", name="rebrickable_set_sets") */ - public function setsAction(Set $set) { + public function setsAction(Set $set) + { $em = $this->getDoctrine()->getManager(); $inventorySets = $em->getRepository(Inventory_Set::class)->findAllBySetNumber($set->getNumber()); @@ -59,6 +57,7 @@ class SetController extends Controller $json = json_encode($template->getContent()); $response = new Response($json, 200); $response->headers->set('Content-Type', 'application/json'); + return $response; } } diff --git a/src/AppBundle/Controller/SetController.php b/src/AppBundle/Controller/SetController.php index 14a1137..0413212 100644 --- a/src/AppBundle/Controller/SetController.php +++ b/src/AppBundle/Controller/SetController.php @@ -4,15 +4,9 @@ namespace AppBundle\Controller; use AppBundle\Api\Exception\ApiException; use AppBundle\Api\Exception\EmptyResponseException; -use AppBundle\Entity\LDraw\Model; -use AppBundle\Entity\Rebrickable\Color; use AppBundle\Entity\Rebrickable\Inventory_Part; -use AppBundle\Entity\Rebrickable\Inventory_Set; -use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Set; -use AppBundle\Entity\Rebrickable\Theme; use AppBundle\Form\Filter\Set\SetFilterType; -use AppBundle\Form\FilterSetType; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; @@ -50,7 +44,7 @@ class SetController extends Controller return $this->render('set/index.html.twig', [ 'sets' => $sets, - 'form' => $form->createView() + 'form' => $form->createView(), ]); } @@ -62,9 +56,9 @@ class SetController extends Controller $rebrickableSet = null; $bricksetSet = null; try { - if(($rebrickableSet = $this->getDoctrine()->getManager()->getRepository(Set::class)->find($number)) == null) { + if (($rebrickableSet = $this->getDoctrine()->getManager()->getRepository(Set::class)->find($number)) == null) { $this->addFlash('warning', 'Set not found in Rebrickable database'); - }; + } $bricksetSet = $this->get('api.manager.brickset')->getSetByNumber($number); dump($bricksetSet); @@ -76,7 +70,7 @@ class SetController extends Controller $this->addFlash('error', $e->getMessage()); } - if(!$rebrickableSet && !$bricksetSet) { + if (!$rebrickableSet && !$bricksetSet) { return $this->render('error/error.html.twig'); } @@ -85,38 +79,4 @@ class SetController extends Controller 'brset' => $bricksetSet, ]); } - - /** - * @Route("/{number}/download", name="set_download") - */ - public function downloadZipAction(Request $request, $number) { - $em = $this->getDoctrine()->getManager(); - - $inventoryParts = $em->getRepository(Inventory_Part::class)->findAllRegularBySetNumber($number); - - $zip = new \ZipArchive(); - $zipName = 'set_'.$number.'.zip'; - $zip->open($zipName, \ZipArchive::CREATE); - /** @var Inventory_Part $part */ - foreach ($inventoryParts as $part) { - $filename = $part->getPart()->getNumber().'_('.$part->getColor()->getName().'_'.$part->getQuantity().'x).stl'; - - try { - if($part->getPart()->getModel()) { - $zip->addFromString($filename, $this->get('oneup_flysystem.media_filesystem')->read($part->getPart()->getModel()->getPath())); - } - } catch (\Exception $e) { - dump($e); - } - } - $zip->close(); - - $response = new Response(file_get_contents($zipName)); - $response->headers->set('Content-Type', 'application/zip'); - $response->headers->set('Content-Disposition', 'attachment;filename="' . $zipName . '"'); - $response->headers->set('Content-length', filesize($zipName)); - - return $response; - } - } diff --git a/src/AppBundle/Entity/Rebrickable/Inventory.php b/src/AppBundle/Entity/Rebrickable/Inventory.php index 3a8efe8..d04c23f 100644 --- a/src/AppBundle/Entity/Rebrickable/Inventory.php +++ b/src/AppBundle/Entity/Rebrickable/Inventory.php @@ -45,7 +45,6 @@ class Inventory */ protected $inventorySets; - public function __construct() { $this->inventoryParts = new ArrayCollection(); diff --git a/src/AppBundle/Exception/ConvertingFailedException.php b/src/AppBundle/Exception/ConvertingFailedException.php index d16c2be..5cf7426 100644 --- a/src/AppBundle/Exception/ConvertingFailedException.php +++ b/src/AppBundle/Exception/ConvertingFailedException.php @@ -2,18 +2,19 @@ namespace AppBundle\Exception; - use Exception; class ConvertingFailedException extends \Exception { private $filepath; - public function __construct($filepath = "", $message = "", $code = 0, Exception $previous = null) + public function __construct($form = '', $to = '', $message = '', $code = 0, Exception $previous = null) { + $message = sprintf('Error converting "%s" file to "%s".', $form, $to); + parent::__construct($message, $code, $previous); - $this->filepath = $filepath; + $this->filepath = $form; } /** @@ -31,6 +32,4 @@ class ConvertingFailedException extends \Exception { $this->filepath = $filepath; } - - -} \ No newline at end of file +} diff --git a/src/AppBundle/Repository/Rebrickable/InventoryRepository.php b/src/AppBundle/Repository/Rebrickable/InventoryRepository.php index 0158186..e542f17 100644 --- a/src/AppBundle/Repository/Rebrickable/InventoryRepository.php +++ b/src/AppBundle/Repository/Rebrickable/InventoryRepository.php @@ -7,12 +7,12 @@ use AppBundle\Repository\BaseRepository; class InventoryRepository extends BaseRepository { - public function findNewestInventoryBySetNumber($number) { - + public function findNewestInventoryBySetNumber($number) + { $queryBuilder = $this->createQueryBuilder('inventory') ->where('inventory.set = :setNumber') ->setParameter('setNumber', $number) - ->orderBy('inventory.version','DESC') + ->orderBy('inventory.version', 'DESC') ->setMaxResults(1); return $queryBuilder->getQuery()->getOneOrNullResult(); diff --git a/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php b/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php index 13f6969..ef63d02 100644 --- a/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php +++ b/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php @@ -6,7 +6,6 @@ use AppBundle\Entity\LDraw\Category; use AppBundle\Entity\Rebrickable\Inventory; use AppBundle\Entity\Rebrickable\Inventory_Part; use AppBundle\Entity\Rebrickable\Part; -use AppBundle\Entity\Rebrickable\Set; use AppBundle\Repository\BaseRepository; use Doctrine\ORM\Query\Expr\Join; @@ -18,7 +17,7 @@ class Inventory_PartRepository extends BaseRepository $queryBuilder = $this->createQueryBuilder('inventory_part') ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory') - ->join(Part::class,'part',JOIN::WITH,'inventory_part.part = part.number') + ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part.number') ->where('part.category != 17') ->andWhere('inventory.id = :inventoryId') ->setParameter('inventoryId', $inventory->getId()) @@ -34,7 +33,7 @@ class Inventory_PartRepository extends BaseRepository $queryBuilder = $this->createQueryBuilder('inventory_part') ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory') - ->join(Part::class,'part',JOIN::WITH,'inventory_part.part = part.number') + ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part.number') ->where('part.category != 17') ->andWhere('inventory.id = :inventoryId') ->setParameter('inventoryId', $inventory->getId()) diff --git a/src/AppBundle/Repository/Rebrickable/Inventory_SetRepository.php b/src/AppBundle/Repository/Rebrickable/Inventory_SetRepository.php index cf0b97d..808d706 100644 --- a/src/AppBundle/Repository/Rebrickable/Inventory_SetRepository.php +++ b/src/AppBundle/Repository/Rebrickable/Inventory_SetRepository.php @@ -3,21 +3,18 @@ namespace AppBundle\Repository\Rebrickable; use AppBundle\Entity\Rebrickable\Inventory; -use AppBundle\Entity\Rebrickable\Inventory_Part; -use AppBundle\Entity\Rebrickable\Set; use AppBundle\Repository\BaseRepository; -use Doctrine\ORM\Query\Expr\Join; class Inventory_SetRepository extends BaseRepository { - public function findAllBySetNumber($number) { - + public function findAllBySetNumber($number) + { $inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number); - if($inventory) { + if ($inventory) { $queryBuilder = $this->createQueryBuilder('inventory_set') ->where('inventory_set.inventory = :inventory') - ->setParameter('inventory',$inventory->getId()); + ->setParameter('inventory', $inventory->getId()); return $queryBuilder->getQuery()->getResult(); } diff --git a/src/AppBundle/Repository/Rebrickable/SetRepository.php b/src/AppBundle/Repository/Rebrickable/SetRepository.php index 2614a47..ce6b591 100644 --- a/src/AppBundle/Repository/Rebrickable/SetRepository.php +++ b/src/AppBundle/Repository/Rebrickable/SetRepository.php @@ -5,7 +5,6 @@ namespace AppBundle\Repository\Rebrickable; use AppBundle\Entity\LDraw\Model; use AppBundle\Entity\Rebrickable\Inventory; use AppBundle\Entity\Rebrickable\Inventory_Part; -use AppBundle\Entity\Rebrickable\Inventory_Set; use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Set; use AppBundle\Entity\Rebrickable\Theme; @@ -14,12 +13,12 @@ use Doctrine\ORM\Query\Expr\Join; class SetRepository extends BaseRepository { - public function findAllByTheme(Theme $theme) { - + public function findAllByTheme(Theme $theme) + { dump($this->getEntityManager()->getRepository(Theme::class)->findAllSubthemes($theme)); $queryBuilder = $this->createQueryBuilder('s') - ->join(Theme::class, 'theme',Join::WITH, 's.theme = theme') + ->join(Theme::class, 'theme', Join::WITH, 's.theme = theme') ->where('theme.id = :id') ->setParameter('id', $theme->getId()); diff --git a/src/AppBundle/Repository/Rebrickable/ThemeRepository.php b/src/AppBundle/Repository/Rebrickable/ThemeRepository.php index 8752161..fcdaccd 100644 --- a/src/AppBundle/Repository/Rebrickable/ThemeRepository.php +++ b/src/AppBundle/Repository/Rebrickable/ThemeRepository.php @@ -8,12 +8,12 @@ use Doctrine\ORM\Query\Expr\Join; class ThemeRepository extends BaseRepository { - public function findAllSubthemes(Theme $theme) { - - $subQueryBuilder = $this->createQueryBuilder('subtheme'); + public function findAllSubthemes(Theme $theme) + { + $subQueryBuilder = $this->createQueryBuilder('subtheme'); $queryBuilder = $this->createQueryBuilder('subtheme') - ->leftJoin(Theme::class,'theme', Join::WITH, 'subtheme.parent = theme.id') + ->leftJoin(Theme::class, 'theme', Join::WITH, 'subtheme.parent = theme.id') ->where('subtheme.parent = :id') ->setParameter('id', $theme->getId()); diff --git a/src/AppBundle/Twig/AppExtension.php b/src/AppBundle/Twig/AppExtension.php index 1c0c0b0..74e3cb1 100644 --- a/src/AppBundle/Twig/AppExtension.php +++ b/src/AppBundle/Twig/AppExtension.php @@ -3,9 +3,6 @@ namespace AppBundle\Twig; use AppBundle\Api\Manager\RebrickableManager; -use AppBundle\Entity\Rebrickable\Color; -use AppBundle\Entity\Rebrickable\Part; -use AppBundle\Entity\Rebrickable\Set; class AppExtension extends \Twig_Extension { @@ -30,7 +27,8 @@ class AppExtension extends \Twig_Extension ]; } - public function getFunctions() { + public function getFunctions() + { return [ new \Twig_SimpleFunction('remoteSize', [$this, 'remoteSize']), new \Twig_SimpleFunction('remoteFilename', [$this, 'remoteFilename']), @@ -39,7 +37,7 @@ class AppExtension extends \Twig_Extension public function partImage($number, $color = null) { - return '/parts/ldraw/'.($color ? $color :'-1').'/'.$number.'.png'; + return '/parts/ldraw/'.($color ? $color : '-1').'/'.$number.'.png'; } public function setImage($number) @@ -47,21 +45,24 @@ class AppExtension extends \Twig_Extension return '/sets/'.strtolower($number).'.jpg'; } - public function remoteSize($url) { + public function remoteSize($url) + { $ch = curl_init($url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_HEADER, TRUE); - curl_setopt($ch, CURLOPT_NOBODY, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_NOBODY, true); $data = curl_exec($ch); $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); curl_close($ch); + return $size; } - public function remoteFilename($url) { - return basename($url); + public function remoteFilename($url) + { + return basename($url); } }