Skip to content

Commit

Permalink
Update coding standard rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Jul 9, 2020
1 parent 4936d99 commit ba78ffe
Show file tree
Hide file tree
Showing 61 changed files with 692 additions and 175 deletions.
31 changes: 24 additions & 7 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
<?php

$header = <<<'HEADER'
This file is part of HackzillaTicketBundle package.
(c) Daniel Platt <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
HEADER;

// Use PHP-CS-Fixer 2+ if it is available
if (\class_exists(PhpCsFixer\Config::class, false)) {
return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'align_double_arrow' => true,
'align_equals' => true,
],
'blank_line_after_opening_tag' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'explicit_string_variable' => true,
'global_namespace_import' => ['import_classes' => false],
'header_comment' => [
'header' => $header,
],
'logical_operators' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'multiline_whitespace_before_semicolons' => true,
'no_alternative_syntax' => true,
'no_extra_blank_lines' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_unset_on_property' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
Expand All @@ -28,6 +45,8 @@ if (\class_exists(PhpCsFixer\Config::class, false)) {
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
'single_line_throw' => false,
'static_lambda' => true,
])
->setFinder(
PhpCsFixer\Finder::create()->exclude(['Tests/Functional/cache'])->in(__DIR__)
Expand All @@ -38,13 +57,11 @@ if (\class_exists(PhpCsFixer\Config::class, false)) {
return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->fixers([
'align_double_arrow',
'header_comment' => $header,
'newline_after_open_tag',
'ordered_use',
'php_unit_construct',
'short_array_syntax',
'-unalign_double_arrow',
'-unalign_equals',
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
Expand Down
12 changes: 0 additions & 12 deletions .styleci.yml

This file was deleted.

18 changes: 13 additions & 5 deletions Command/AutoClosingCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\Command;

use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
Expand Down Expand Up @@ -35,8 +44,7 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'How many days since the ticket was resolved?',
'10'
)
;
);
}

/**
Expand All @@ -48,11 +56,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName()));
}

$ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager');
$userManager = $this->getContainer()->get('fos_user.user_manager');
$ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager');
$userManager = $this->getContainer()->get('fos_user.user_manager');
$ticketRepository = $this->getContainer()->get('doctrine')->getRepository('HackzillaTicketBundle:Ticket');

$locale = $this->getContainer()->getParameter('locale') ? $this->getContainer()->getParameter('locale') : 'en';
$locale = $this->getContainer()->getParameter('locale') ? $this->getContainer()->getParameter('locale') : 'en';
$translator = $this->getContainer()->get('translator');
$translator->setLocale($locale);

Expand Down
12 changes: 10 additions & 2 deletions Command/TicketManagerCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\Command;

use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
Expand Down Expand Up @@ -40,8 +49,7 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'What priority would it be?',
'21'
)
;
);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Component/TicketFeatures.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\Component;

use Hackzilla\Bundle\TicketBundle\Model\TicketFeature\MessageAttachmentInterface;
Expand Down
9 changes: 9 additions & 0 deletions Controller/TicketAttachmentController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\Controller;

use Hackzilla\Bundle\TicketBundle\Entity\TicketMessageWithAttachment;
Expand Down
39 changes: 24 additions & 15 deletions Controller/TicketController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\Controller;

use Hackzilla\Bundle\TicketBundle\Event\TicketEvent;
Expand Down Expand Up @@ -27,12 +36,12 @@ class TicketController extends Controller
*/
public function indexAction(Request $request)
{
$userManager = $this->getUserManager();
$userManager = $this->getUserManager();
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');

$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

$ticketState = $request->get('state', $this->get('translator')->trans('STATUS_OPEN', [], $translationDomain));
$ticketState = $request->get('state', $this->get('translator')->trans('STATUS_OPEN', [], $translationDomain));
$ticketPriority = $request->get('priority', null);

$query = $ticketManager->getTicketListQuery(
Expand All @@ -50,9 +59,9 @@ public function indexAction(Request $request)
return $this->render(
$this->container->getParameter('hackzilla_ticket.templates')['index'],
[
'pagination' => $pagination,
'ticketState' => $ticketState,
'ticketPriority' => $ticketPriority,
'pagination' => $pagination,
'ticketState' => $ticketState,
'ticketPriority' => $ticketPriority,
'translationDomain' => $translationDomain,
]
);
Expand All @@ -68,7 +77,7 @@ public function createAction(Request $request)
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');

$ticket = $ticketManager->createTicket();
$form = $this->createForm(TicketType::class, $ticket);
$form = $this->createForm(TicketType::class, $ticket);
$form->handleRequest($request);

if ($form->isValid()) {
Expand All @@ -87,8 +96,8 @@ public function createAction(Request $request)
return $this->render(
$this->container->getParameter('hackzilla_ticket.templates')['new'],
[
'entity' => $ticket,
'form' => $form->createView(),
'entity' => $ticket,
'form' => $form->createView(),
'translationDomain' => $translationDomain,
]
);
Expand All @@ -100,7 +109,7 @@ public function createAction(Request $request)
public function newAction()
{
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
$entity = $ticketManager->createTicket();
$entity = $ticketManager->createTicket();

$form = $this->createForm(TicketType::class, $entity);

Expand All @@ -109,8 +118,8 @@ public function newAction()
return $this->render(
$this->container->getParameter('hackzilla_ticket.templates')['new'],
[
'entity' => $entity,
'form' => $form->createView(),
'entity' => $entity,
'form' => $form->createView(),
'translationDomain' => $translationDomain,
]
);
Expand All @@ -126,7 +135,7 @@ public function newAction()
public function showAction($ticketId)
{
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
$ticket = $ticketManager->getTicketById($ticketId);
$ticket = $ticketManager->getTicketById($ticketId);

if (!$ticket) {
return $this->redirect($this->generateUrl('hackzilla_ticket'));
Expand Down Expand Up @@ -162,7 +171,7 @@ public function showAction($ticketId)
public function replyAction(Request $request, $ticketId)
{
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
$ticket = $ticketManager->getTicketById($ticketId);
$ticket = $ticketManager->getTicketById($ticketId);

$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');

Expand Down Expand Up @@ -205,7 +214,7 @@ public function replyAction(Request $request, $ticketId)
public function deleteAction(Request $request, $ticketId)
{
$userManager = $this->getUserManager();
$user = $userManager->getCurrentUser();
$user = $userManager->getCurrentUser();

if (!\is_object($user) || !$userManager->hasRole($user, TicketRole::ADMIN)) {
throw new \Symfony\Component\HttpKernel\Exception\HttpException(403);
Expand All @@ -218,7 +227,7 @@ public function deleteAction(Request $request, $ticketId)

if ($form->isValid()) {
$ticketManager = $this->get('hackzilla_ticket.ticket_manager');
$ticket = $ticketManager->getTicketById($ticketId);
$ticket = $ticketManager->getTicketById($ticketId);

if (!$ticket) {
$translationDomain = $this->getParameter('hackzilla_ticket.translation_domain');
Expand Down
33 changes: 23 additions & 10 deletions DependencyInjection/Compiler/DoctrineOrmMappingsPass.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\DependencyInjection\Compiler;

use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Hackzilla\Bundle\TicketBundle\DependencyInjection\HackzillaTicketExtension;
use Hackzilla\Bundle\TicketBundle\Entity\Ticket;
use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
use Hackzilla\Bundle\TicketBundle\Entity\TicketMessageWithAttachment;
use Hackzilla\Bundle\TicketBundle\Entity\TicketWithAttachment;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

Expand All @@ -19,25 +34,23 @@ public function __construct($driver = null, array $namespaces = [], $managerPara
public function process(ContainerBuilder $container)
{
$bundleDirectory = HackzillaTicketExtension::bundleDirectory();
$namespaces = [];
$namespaces = [];

if (
'Hackzilla\Bundle\TicketBundle\Entity\TicketWithAttachment' === $container->getParameter('hackzilla_ticket.model.ticket.class')
||
'Hackzilla\Bundle\TicketBundle\Entity\TicketMessageWithAttachment' === $container->getParameter('hackzilla_ticket.model.message.class')
TicketWithAttachment::class === $container->getParameter('hackzilla_ticket.model.ticket.class') ||
TicketMessageWithAttachment::class === $container->getParameter('hackzilla_ticket.model.message.class')
) {
$namespaces[realpath($bundleDirectory.'/Resources/config/doctrine/model/attachment')] = 'Hackzilla\Bundle\TicketBundle\Entity';
} elseif (
'Hackzilla\Bundle\TicketBundle\Entity\Ticket' === $container->getParameter('hackzilla_ticket.model.ticket.class')
||
'Hackzilla\Bundle\TicketBundle\Entity\TicketMessage' === $container->getParameter('hackzilla_ticket.model.message.class')
Ticket::class === $container->getParameter('hackzilla_ticket.model.ticket.class') ||
TicketMessage::class === $container->getParameter('hackzilla_ticket.model.message.class')
) {
$namespaces[realpath($bundleDirectory.'/Resources/config/doctrine/model/plain')] = 'Hackzilla\Bundle\TicketBundle\Entity';
}

$arguments = [$namespaces, '.orm.xml'];
$locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments);
$this->driver = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', [$locator]);
$arguments = [$namespaces, '.orm.xml'];
$locator = new Definition(SymfonyFileLocator::class, $arguments);
$this->driver = new Definition(XmlDriver::class, [$locator]);
$this->namespaces = $namespaces;

parent::process($container);
Expand Down
12 changes: 10 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -54,8 +63,7 @@ public function getConfigTreeBuilder()
->scalarNode('macros')->defaultValue('@HackzillaTicket/Macros/macros.html.twig')->end()
->end()
->end()
->end()
;
->end();

return $treeBuilder;
}
Expand Down
Loading

0 comments on commit ba78ffe

Please sign in to comment.