1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-16 20:30:09 -07:00

Fix coding style

This commit is contained in:
Unknown 2017-06-02 03:27:22 +02:00
parent 71bb607772
commit 85ec4e5481
28 changed files with 82 additions and 79 deletions

View File

@ -21,7 +21,7 @@ services:
service.set: service.set:
class: AppBundle\Service\SetService class: AppBundle\Service\SetService
arguments: ['@repository.rebrickable.inventorypart'] arguments: ['@repository.rebrickable.inventoryPart']
service.model: service.model:
class: AppBundle\Service\ModelService class: AppBundle\Service\ModelService

View File

@ -38,6 +38,8 @@ class Rebrickable_v3
* @param $uri * @param $uri
* @param array $options * @param array $options
* *
* @throws ApiException
*
* @return string * @return string
*/ */
public function call($method, $uri, $options = []) public function call($method, $uri, $options = [])

View File

@ -20,6 +20,7 @@ class BricksetManager
* BricksetManager constructor. * BricksetManager constructor.
* *
* @param Brickset $bricksetClient * @param Brickset $bricksetClient
* @param CacheProvider $cache
*/ */
public function __construct(Brickset $bricksetClient, CacheProvider $cache) public function __construct(Brickset $bricksetClient, CacheProvider $cache)
{ {

View File

@ -4,7 +4,6 @@ namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;

View File

@ -5,7 +5,6 @@ namespace AppBundle\Command;
use AppBundle\Service\Loader\ModelLoader; use AppBundle\Service\Loader\ModelLoader;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\LockableTrait; use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;

View File

@ -20,6 +20,7 @@ class DefaultController extends Controller
/** @var SetRepository $setRepository */ /** @var SetRepository $setRepository */
$setRepository = $this->get('repository.rebrickable.set'); $setRepository = $this->get('repository.rebrickable.set');
return $this->render('default/index.html.twig', [ return $this->render('default/index.html.twig', [
'models' => $modelRepository->count(), 'models' => $modelRepository->count(),
'sets' => $setRepository->count(), 'sets' => $setRepository->count(),

View File

@ -4,7 +4,6 @@ namespace AppBundle\Controller;
use AppBundle\Api\Exception\EmptyResponseException; use AppBundle\Api\Exception\EmptyResponseException;
use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Part;
use AppBundle\Entity\Rebrickable\Set;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;

View File

@ -9,9 +9,7 @@ use AppBundle\Model\SetSearch;
use AppBundle\Repository\Search\ModelRepository; use AppBundle\Repository\Search\ModelRepository;
use AppBundle\Repository\Search\SetRepository; use AppBundle\Repository\Search\SetRepository;
use FOS\ElasticaBundle\HybridResult; use FOS\ElasticaBundle\HybridResult;
use FOS\ElasticaBundle\Repository;
use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Cache\Resolver\CacheResolver;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;

View File

@ -90,7 +90,6 @@ class SetController extends Controller
$setService = $this->get('service.set'); $setService = $this->get('service.set');
$inventoryPartRepository = $this->get('repository.rebrickable.inventoryPart'); $inventoryPartRepository = $this->get('repository.rebrickable.inventoryPart');
$models = $setService->getModels($set, false); $models = $setService->getModels($set, false);
$missing = $setService->getParts($set, false, false); $missing = $setService->getParts($set, false, false);
$missingCount = $inventoryPartRepository->getPartCount($set, false, false); $missingCount = $inventoryPartRepository->getPartCount($set, false, false);

View File

@ -2,7 +2,6 @@
namespace AppBundle\DataFixtures\ORM; namespace AppBundle\DataFixtures\ORM;
use AppBundle\Entity\Color; use AppBundle\Entity\Color;
use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;

View File

@ -81,7 +81,8 @@ class Theme
return $this; return $this;
} }
public function getFullName() { public function getFullName()
{
$theme = $this; $theme = $this;
$name = []; $name = [];

View File

@ -62,6 +62,7 @@ class SetSearchType extends AbstractType
'choice_translation_domain' => false, 'choice_translation_domain' => false,
'group_by' => function ($theme, $key, $index) { 'group_by' => function ($theme, $key, $index) {
$parent = $theme->getParent(); $parent = $theme->getParent();
return $parent ? $parent->getParent() ? $parent->getParent()->getName() : $parent->getName() : $theme->getName(); return $parent ? $parent->getParent() ? $parent->getParent()->getName() : $parent->getName() : $theme->getName();
}, },
'choice_value' => 'id', 'choice_value' => 'id',
@ -79,7 +80,7 @@ class SetSearchType extends AbstractType
$resolver->setDefaults([ $resolver->setDefaults([
'csrf_protection' => false, 'csrf_protection' => false,
'data_class' => SetSearch::class, 'data_class' => SetSearch::class,
'method' => 'GET' 'method' => 'GET',
]); ]);
} }

View File

@ -38,7 +38,8 @@ class PartImageLoader extends BaseImageLoader
// try to load image from rebrickable website // try to load image from rebrickable website
try { try {
if ($this->remoteFileExists($this->rebrickableContext.$path)) { if ($this->remoteFileExists($this->rebrickableContext.$path)) {
$context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n'))); $context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context); return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
} }
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -32,7 +32,8 @@ class SetImageLoader extends BaseImageLoader
// try to load image from rebrickable website // try to load image from rebrickable website
try { try {
if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) { if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) {
$context = stream_context_create(array('http' => array('header'=>'Connection: close\r\n'))); $context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context); return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
} }
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -3,7 +3,6 @@
namespace AppBundle\Menu; namespace AppBundle\Menu;
use Knp\Menu\FactoryInterface; use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
class Builder class Builder
@ -26,7 +25,6 @@ class Builder
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
} }
public function mainMenu(array $options) public function mainMenu(array $options)
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
@ -46,7 +44,7 @@ class Builder
'routeParameters' => ['id' => $request->get('id', 0)], 'routeParameters' => ['id' => $request->get('id', 0)],
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('id', 0) 'value' => $request->get('id', 0),
], ],
]); ]);
@ -54,7 +52,7 @@ class Builder
'route' => 'set_index', 'route' => 'set_index',
'options' => [ 'options' => [
// 'icon' => 'edit', // 'icon' => 'edit',
] ],
]); ]);
$sets->addChild('page.set.detail', [ $sets->addChild('page.set.detail', [
@ -62,7 +60,7 @@ class Builder
'routeParameters' => ['id' => $request->get('id', 0)], 'routeParameters' => ['id' => $request->get('id', 0)],
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('id', 0) 'value' => $request->get('id', 0),
], ],
]); ]);
@ -70,7 +68,7 @@ class Builder
'route' => 'search_results', 'route' => 'search_results',
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('query', 0) 'value' => $request->get('query', 0),
], ],
]); ]);
@ -83,7 +81,7 @@ class Builder
'display' => false, 'display' => false,
'options' => [ 'options' => [
// 'icon' => 'edit', // 'icon' => 'edit',
] ],
]); ]);
$parts->addChild('page.part.detail', [ $parts->addChild('page.part.detail', [
@ -91,11 +89,10 @@ class Builder
'routeParameters' => ['id' => $request->get('id', 0)], 'routeParameters' => ['id' => $request->get('id', 0)],
'display' => false, 'display' => false,
'extras' => [ 'extras' => [
'value' => $request->get('id', 0) 'value' => $request->get('id', 0),
], ],
]); ]);
return $menu; return $menu;
} }
} }

View File

@ -14,6 +14,7 @@ class ModelSearch
/** /**
* ModelSearch constructor. * ModelSearch constructor.
*
* @param string $query * @param string $query
*/ */
public function __construct($query = '') public function __construct($query = '')

View File

@ -20,6 +20,7 @@ class SetSearch
/** /**
* SetSearch constructor. * SetSearch constructor.
*
* @param string $query * @param string $query
*/ */
public function __construct($query = '') public function __construct($query = '')

View File

@ -106,7 +106,8 @@ class ModelRepository extends BaseRepository
return $queryBuilder->getQuery()->getResult(); return $queryBuilder->getQuery()->getResult();
} }
public function count() { public function count()
{
$queryBuilder = $this->createQueryBuilder('model'); $queryBuilder = $this->createQueryBuilder('model');
$queryBuilder->select('count(model)'); $queryBuilder->select('count(model)');

View File

@ -73,7 +73,8 @@ class SetRepository extends BaseRepository
return $queryBuilder->getQuery()->getSingleScalarResult(); return $queryBuilder->getQuery()->getSingleScalarResult();
} }
public function count() { public function count()
{
$queryBuilder = $this->createQueryBuilder('s'); $queryBuilder = $this->createQueryBuilder('s');
$queryBuilder->select('count(s)'); $queryBuilder->select('count(s)');

View File

@ -10,9 +10,11 @@ class ModelRepository extends Repository
{ {
/** /**
* @param ModelSearch $modelSearch * @param ModelSearch $modelSearch
*
* @return \Elastica\Query * @return \Elastica\Query
*/ */
public function getSearchQuery(ModelSearch $modelSearch) { public function getSearchQuery(ModelSearch $modelSearch)
{
$boolQuery = new Query\BoolQuery(); $boolQuery = new Query\BoolQuery();
if ($searchQuery = $modelSearch->getQuery()) { if ($searchQuery = $modelSearch->getQuery()) {
@ -23,7 +25,6 @@ class ModelRepository extends Repository
$query->setFuzziness(0.7); $query->setFuzziness(0.7);
$query->setMinimumShouldMatch('80%'); $query->setMinimumShouldMatch('80%');
$query->setOperator('and'); $query->setOperator('and');
} else { } else {
$query = new Query\MatchAll(); $query = new Query\MatchAll();
} }
@ -42,10 +43,12 @@ class ModelRepository extends Repository
public function search(ModelSearch $modelSearch, $limit = 500) public function search(ModelSearch $modelSearch, $limit = 500)
{ {
$query = $this->getSearchQuery($modelSearch); $query = $this->getSearchQuery($modelSearch);
return $this->find($query, $limit); return $this->find($query, $limit);
} }
public function findHighlighted($query, $limit = 500) { public function findHighlighted($query, $limit = 500)
{
$modelSearch = new ModelSearch(); $modelSearch = new ModelSearch();
$modelSearch->setQuery($query); $modelSearch->setQuery($query);
@ -55,10 +58,10 @@ class ModelRepository extends Repository
$query->setHighlight([ $query->setHighlight([
'pre_tags' => ['<em>'], 'pre_tags' => ['<em>'],
'post_tags' => ['</em>'], 'post_tags' => ['</em>'],
"fields" => [ 'fields' => [
"name" => new \stdClass(), 'name' => new \stdClass(),
"id" => new \stdClass() 'id' => new \stdClass(),
] ],
]); ]);
return $this->findHybrid($query, $limit); return $this->findHybrid($query, $limit);

View File

@ -6,18 +6,18 @@ use AppBundle\Model\SetSearch;
use Elastica\Query; use Elastica\Query;
use Elastica\Query\BoolQuery; use Elastica\Query\BoolQuery;
use Elastica\Query\Match; use Elastica\Query\Match;
use Elastica\Query\MultiMatch;
use Elastica\Query\Range; use Elastica\Query\Range;
use Elastica\Query\Wildcard;
use FOS\ElasticaBundle\Repository; use FOS\ElasticaBundle\Repository;
class SetRepository extends Repository class SetRepository extends Repository
{ {
/** /**
* @param SetSearch $setSearch * @param SetSearch $setSearch
*
* @return Query * @return Query
*/ */
public function getSearchQuery(SetSearch $setSearch) { public function getSearchQuery(SetSearch $setSearch)
{
$boolQuery = new BoolQuery(); $boolQuery = new BoolQuery();
if ($searchQuery = $setSearch->getQuery()) { if ($searchQuery = $setSearch->getQuery()) {
@ -69,7 +69,8 @@ class SetRepository extends Repository
return $this->find($query, $limit); return $this->find($query, $limit);
} }
public function findHighlighted($query, $limit = 500) { public function findHighlighted($query, $limit = 500)
{
$setSearch = new SetSearch(); $setSearch = new SetSearch();
$setSearch->setQuery($query); $setSearch->setQuery($query);
@ -79,10 +80,10 @@ class SetRepository extends Repository
$query->setHighlight([ $query->setHighlight([
'pre_tags' => ['<em>'], 'pre_tags' => ['<em>'],
'post_tags' => ['</em>'], 'post_tags' => ['</em>'],
"fields" => [ 'fields' => [
"name" => new \stdClass(), 'name' => new \stdClass(),
"id" => new \stdClass() 'id' => new \stdClass(),
] ],
]); ]);
return $this->findHybrid($query, $limit); return $this->findHybrid($query, $limit);

View File

@ -10,7 +10,6 @@ use Monolog\Logger;
use Symfony\Bundle\FrameworkBundle\Translation\Translator; use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\Asset\Exception\LogicException; use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Debug\Exception\ContextErrorException; use Symfony\Component\Debug\Exception\ContextErrorException;

View File

@ -19,8 +19,6 @@ use AppBundle\Util\RelationMapper;
use League\Flysystem\Adapter\Local; use League\Flysystem\Adapter\Local;
use League\Flysystem\Exception; use League\Flysystem\Exception;
use League\Flysystem\Filesystem; use League\Flysystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
class ModelLoader extends BaseLoader class ModelLoader extends BaseLoader
{ {
@ -116,7 +114,7 @@ class ModelLoader extends BaseLoader
} }
/** /**
* Load one model into database * Load one model into database.
* *
* @param string $file Absolute filepath of model to load * @param string $file Absolute filepath of model to load
*/ */
@ -140,9 +138,8 @@ 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() public function loadAll()
{ {
@ -331,8 +328,7 @@ class ModelLoader extends BaseLoader
// Try to find model in current file's directory // Try to find model in current file's directory
if ($this->fileContext && $this->fileContext->has($filename)) { if ($this->fileContext && $this->fileContext->has($filename)) {
return $this->fileContext->getAdapter()->getPathPrefix().$filename; return $this->fileContext->getAdapter()->getPathPrefix().$filename;
} } elseif ($this->ldrawLibraryContext) {
elseif ($this->ldrawLibraryContext) {
// Try to find model in current LDRAW\PARTS sub-directory // Try to find model in current LDRAW\PARTS sub-directory
if ($this->ldrawLibraryContext->has('parts'.DIRECTORY_SEPARATOR.$filename)) { if ($this->ldrawLibraryContext->has('parts'.DIRECTORY_SEPARATOR.$filename)) {
return $this->ldrawLibraryContext->getAdapter()->getPathPrefix().'parts'.DIRECTORY_SEPARATOR.$filename; return $this->ldrawLibraryContext->getAdapter()->getPathPrefix().'parts'.DIRECTORY_SEPARATOR.$filename;

View File

@ -73,12 +73,14 @@ class AppExtension extends \Twig_Extension
return $size; return $size;
} }
public function fileTimestamp($filePath) { public function fileTimestamp($filePath)
{
$changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath); $changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath);
if (!$changeDate) { if (!$changeDate) {
//Fallback if mtime could not be found: //Fallback if mtime could not be found:
$changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
} }
return $filePath.'?'.$changeDate; return $filePath.'?'.$changeDate;
} }