Commit dcb8b46b authored by Hermann Mayer's avatar Hermann Mayer

Finished DI refactoring. (Via annotations) Cleaned up some messes, detected by…

Finished DI refactoring. (Via annotations) Cleaned up some messes, detected by phpmd. Shrinked minimum variable name length to 2. Converted Tag Entity 'match' property from public to protected, to fix doctrine validation messing.
parent db1c7ec0
......@@ -12,7 +12,7 @@
/.project
/nbproject/
/build/
/build/*/*
/src/cache.properties
/web/css/*
......
......@@ -68,7 +68,7 @@
<target name="phpmd-ci" description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
<exec executable="phpmd">
<arg line="
${basedir} xml codesize,unusedcode,naming,design --reportfile ${output}/logs/pmd.xml --exclude Tests/
${basedir} xml ${basedir}/../build/phpmd.xml --reportfile ${output}/logs/pmd.xml --exclude Tests/
" />
</exec>
</target>
......
<?xml version="1.0"?>
<ruleset name="Horde PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Jack's custom PHPMD rule set.
</description>
<!-- Import the entire unused code rule set -->
<rule ref="rulesets/codesize.xml" />
<!-- <rule ref="rulesets/controversial.xml" /> -->
<rule ref="rulesets/design.xml" />
<!-- <rule ref="rulesets/naming.xml" /> -->
<rule ref="rulesets/unusedcode.xml" />
<!-- Import entire naming rule set and exclude rules -->
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
</rule>
<!-- Import the entire ShortVariable rule and
customize the rule configuration. -->
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="minimum" value="2" />
</properties>
</rule>
</ruleset>
......@@ -254,14 +254,14 @@ class ArticleController extends Controller
$entity->removeTag($tag);
$tag = $em->merge($tag);
array_walk($postData['tags'], function($item, $key) use($tag)
array_walk($postData['tags'], function($item) use($tag)
{
if ($item['name'] == $tag->getName()) {
$tag->match = $item['match'];
$tag->setContextMatch($item['contextMatch']);
}
});
$entity->addTag($tag, $tag->match);
$entity->addTag($tag, $tag->getContextMatch());
}
}
......
......@@ -80,7 +80,7 @@ class BlogController extends Controller
$em = $this->getDoctrine()->getManager();
// Use DQL because its more powerfull and only one query is needed
$q = $em->createQueryBuilder()
$query = $em->createQueryBuilder()
->select('a.createdAt')
->from('JityHomepageBundle:Article', 'a')
->getQuery();
......@@ -88,7 +88,7 @@ class BlogController extends Controller
$archivMap = array();
// Map the archiv
foreach ($q->getArrayResult() as $entity) {
foreach ($query->getArrayResult() as $entity) {
$date = $entity['createdAt'];
$year = $date->format('Y');
......
......@@ -185,9 +185,6 @@ class DefaultController extends Controller
$pages = array_merge($pages, $nav->getPages()->toArray());
}
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
return $this->render('JityHomepageBundle:Default:navigation.html.twig', array(
'pages' => $pages,
'currentSlug' => $currentSlug
......
......@@ -39,13 +39,13 @@ class SectionController extends Controller
$em = $this->getDoctrine()->getManager();
// Use DQL because its more powerfull and only one query is needed
$q = $em->createQueryBuilder('s')
$query = $em->createQueryBuilder('s')
->select('s.id, s.title')
->from('JityHomepageBundle:Section', 's')
->getQuery();
return new Response(
json_encode($q->getArrayResult())
json_encode($query->getArrayResult())
);
}
......
......@@ -39,13 +39,13 @@ class TagController extends Controller
$em = $this->getDoctrine()->getManager();
// Use DQL because its more powerfull and only one query is needed
$q = $em->createQueryBuilder()
$query = $em->createQueryBuilder()
->select('t.id, t.name')
->from('JityHomepageBundle:Tag', 't')
->getQuery();
return new Response(
json_encode($q->getArrayResult())
json_encode($query->getArrayResult())
);
}
......
......@@ -35,8 +35,6 @@ class UserController extends Controller
*/
public function showDashboardAction()
{
$em = $this->getDoctrine()->getEntityManager();
// Try to find a valid user object
$entity = $this->container->get('security.context')->getToken()->getUser();
......@@ -70,8 +68,6 @@ class UserController extends Controller
return $this->redirect($this->generateUrl('user_dashboard'));
}
$em = $this->getDoctrine()->getEntityManager();
// Try to find a valid user object
$entity = $this->container->get('security.context')->getToken()->getUser();
......
......@@ -15,7 +15,8 @@ use Doctrine\ORM\EntityManager,
Doctrine\ORM\NoResultException,
HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface,
HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface,
Jity\HomepageBundle\Entity\User;
Jity\HomepageBundle\Entity\User,
JMS\DiExtraBundle\Annotation as DI;
/**
* OAuthUserProvider
......@@ -23,6 +24,8 @@ use Doctrine\ORM\EntityManager,
* Custom OAuthUserProvider implementation, to build a
* auto-register-on-login functionality.
*
* @DI\Service("jity.oauth.user_provider")
*
* @uses OAuthAwareUserProviderInterface
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
......@@ -30,7 +33,6 @@ class OAuthUserProvider implements OAuthAwareUserProviderInterface
{
private $em;
private $session;
private $response;
/**
* __construct
......@@ -40,6 +42,11 @@ class OAuthUserProvider implements OAuthAwareUserProviderInterface
* @param EntityManager $em DI Injected Doctrine Entity Manager
* @param mixed $session DI Injected Session Object
*
* @DI\InjectParams({
* "em" = @DI\Inject("doctrine.orm.entity_manager"),
* "session" = @DI\Inject("session")
* })
*
* @access public
* @return void
*/
......@@ -62,7 +69,7 @@ class OAuthUserProvider implements OAuthAwareUserProviderInterface
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$q = $this->em
$query = $this->em
->createQueryBuilder()
->select('u')
->from('JityHomepageBundle:User', 'u')
......@@ -74,7 +81,7 @@ class OAuthUserProvider implements OAuthAwareUserProviderInterface
// The Query::getSingleResult() method throws an exception
// if there is no record matching the criteria.
$user = $q->getSingleResult();
$user = $query->getSingleResult();
} catch (NoResultException $e) {
......
......@@ -12,6 +12,7 @@
namespace Jity\HomepageBundle\DependencyInjection;
use Doctrine\ORM\EntityManager,
JMS\DiExtraBundle\Annotation as DI,
\Symfony\Component\Security\Core\Role\RoleHierarchy as SymfonyRoleHierarchy;
/**
......@@ -20,6 +21,9 @@ use Doctrine\ORM\EntityManager,
* Custom RoleHierarchy implementation to handle
* dynamically loaded roles from a database.
*
* @DI\Service("security.role_hierarchy")
* @DI\Tag("security.role_hierarchy")
*
* @uses SymfonyRoleHierarchy
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
......@@ -35,6 +39,11 @@ class RoleHierarchy extends SymfonyRoleHierarchy
* @param array $hierarchy DI Injected Role Hierarchy
* @param EntityManager $em DI Injected Doctrine Entity Manager
*
* @DI\InjectParams({
* "hierarchy" = @DI\Inject("%security.role_hierarchy.roles%"),
* "em" = @DI\Inject("doctrine.orm.entity_manager")
* })
*
* @access public
* @return void
*/
......@@ -61,13 +70,13 @@ class RoleHierarchy extends SymfonyRoleHierarchy
// $roles = $this->em->getRepository('JityHomepageBundle:Group')->findAll();
// Use DQL because its more powerfull and only one query is needed
$q = $this->em->createQueryBuilder('u')
$query = $this->em->createQueryBuilder('u')
->select('g, p')
->from('JityHomepageBundle:Group', 'g')
->leftJoin('g.parents', 'p')
->getQuery();
$roles = $q->getResult();
$roles = $query->getResult();
// Build new hierarchy map as array
foreach ($roles as $role) {
......
......@@ -537,7 +537,7 @@ abstract class AbstractPage
$rel = new \Jity\HomepageBundle\Entity\AbstractPageTag($this, $tag);
if (null === $match) {
$match = $tag->match;
$match = $tag->getContextMatch();
}
$rel->setMatch($match);
......@@ -588,7 +588,7 @@ abstract class AbstractPage
foreach ($this->abstractPageTag as $rel) {
$tag = $rel->getTag();
$tag->match = $rel->getMatch();
$tag->setContextMatch($rel->getMatch());
$collection->add($tag);
}
......
......@@ -63,7 +63,7 @@ class Article extends AbstractPage
public function addComment(\Jity\HomepageBundle\Entity\Comment $comment)
{
$this->comments[] = $comment;
$comments->setArticle($this);
$comment->setArticle($this);
return $this;
}
......
......@@ -241,50 +241,5 @@ class Section
return $collection;
}
/**
* addSidebarSection
*
* Add a sidebarSection to the entity.
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sidebarSection SidebarSection to add
*
* @access public
* @return Section
*/
public function addSidebarSection(\Jity\HomepageBundle\Entity\SidebarSection $sidebarSection)
{
$this->sidebarSection[] = $sidebarSection;
return $this;
}
/**
* removeSidebarSection
*
* Remove a assigned sidebarSection of the entity.
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sidebarSection SidebarSection to remove
*
* @access public
* @return Section
*/
public function removeSidebarSection(\Jity\HomepageBundle\Entity\SidebarSection $sidebarSection)
{
$this->sidebarSection->removeElement($sidebarSection);
}
/**
* getSidebarSection
*
* Get the sidebarSection assigned to the entity.
*
* @access public
* @return Doctrine\Common\Collections\Collection
*/
public function getSidebarSection()
{
return $this->sidebarSection;
}
}
......@@ -235,50 +235,5 @@ class Sidebar
{
return $this->pages;
}
/**
* addSidebarSection
*
* Add a sidebarSection to the entity.
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sidebarSection SidebarSection to add
*
* @access public
* @return Sidebar
*/
public function addSidebarSection(\Jity\HomepageBundle\Entity\SidebarSection $sidebarSection)
{
$this->sidebarSection[] = $sidebarSection;
return $this;
}
/**
* removeSidebarSection
*
* Remove a assigned sidebarSection of the entity.
*
* @param Jity\HomepageBundle\Entity\SidebarSection $sidebarSection SidebarSection to remove
*
* @access public
* @return Sidebar
*/
public function removeSidebarSection(\Jity\HomepageBundle\Entity\SidebarSection $sidebarSection)
{
$this->sidebarSection->removeElement($sidebarSection);
}
/**
* getSidebarSection
*
* Get the assigned sidebarSection of the entity.
*
* @access public
* @return Doctrine\Common\Collections\Collection
*/
public function getSidebarSection()
{
return $this->sidebarSection;
}
}
......@@ -56,10 +56,10 @@ class Tag
protected $abstractPageTag;
/**
* @var match
* @var contextMatch
* @Exclude
*/
public $match;
protected $contextMatch;
/**
......@@ -205,5 +205,35 @@ class Tag
return $collection;
}
/**
* setContextMatch
*
* Set name of the entity.
*
* @param int $match Matching of the tag (not persist)
*
* @access public
* @return Tag
*/
public function setContextMatch($match)
{
$this->contextMatch = $match;
return $this;
}
/**
* getContextMatch
*
* Get the matching of the entity. (not persist)
*
* @access public
* @return string
*/
public function getContextMatch()
{
return $this->contextMatch;
}
}
......@@ -41,7 +41,7 @@ class UserRepository extends EntityRepository implements UserProviderInterface
*/
public function loadUserByUsername($username)
{
$q = $this
$query = $this
->createQueryBuilder('u')
->select('u, g')
->leftJoin('u.groups', 'g')
......@@ -52,7 +52,7 @@ class UserRepository extends EntityRepository implements UserProviderInterface
try {
// The Query::getSingleResult() method throws an exception
// if there is no record matching the criteria.
$user = $q->getSingleResult();
$user = $query->getSingleResult();
} catch (NoResultException $e) {
......
......@@ -42,7 +42,7 @@ class ControllerListener
*
* @DI\InjectParams({
* "request" = @DI\Inject("request"),
* "router" = @DI\Inject("router")
* "router" = @DI\Inject("router")
* })
*
* @access public
......@@ -69,7 +69,7 @@ class ControllerListener
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
// Get controller object for further processing
$controller = $event->getController();
// $controller = $event->getController();
// // Print Information about the current route
// $route = $this->router->match($this->request->getPathInfo());
......
......@@ -45,7 +45,7 @@ class LoginSuccessListener implements AuthenticationSuccessHandlerInterface
*
* @DI\InjectParams({
* "session" = @DI\Inject("session"),
* "router" = @DI\Inject("router")
* "router" = @DI\Inject("router")
* })
*
* @access public
......
......@@ -57,7 +57,7 @@ class ArticleType extends AbstractType
'class' => 'sortable-existing'
),
'lists' => array (
'element' => 'match',
'element' => 'contextMatch',
'values' => array(100, 66, 33),
'labels' => array(
100 => '<h3>Sehr zutreffend</h3>',
......
......@@ -43,7 +43,7 @@ class TagType extends AbstractType
->add('name', null, array(
'label' => 'Name'
))
->add('match', 'hidden');
->add('contextMatch', 'hidden');
}
/**
......
......@@ -6,7 +6,12 @@ parameters:
# jity_homepage.example.class: Jity\HomepageBundle\Example
services:
#
# Our big switch is done. We define every service via anotations.
# Thanks to the greate JMS/Extra-DI-Bundle.
#
#
# Example Service.
#
......@@ -26,11 +31,11 @@ services:
# Oerwrite the default RoleHierarchy class to handle
# role hierarchy dynamically.
#
security.role_hierarchy:
class: Jity\HomepageBundle\DependencyInjection\RoleHierarchy
arguments: [ %security.role_hierarchy.roles%, @doctrine.orm.entity_manager ]
tags:
- { name: security.role_hierarchy }
# security.role_hierarchy:
# class: Jity\HomepageBundle\DependencyInjection\RoleHierarchy
# arguments: [ %security.role_hierarchy.roles%, @doctrine.orm.entity_manager ]
# tags:
# - { name: security.role_hierarchy }
#
# Use a custom Twig extension to parse twig code
......@@ -44,9 +49,9 @@ services:
#
# Custom Logic for OAuth Logins.
#
jity.oauth.user_provider:
class: Jity\HomepageBundle\DependencyInjection\OAuthUserProvider
arguments: [ @doctrine.orm.entity_manager, @session ]
# jity.oauth.user_provider:
# class: Jity\HomepageBundle\DependencyInjection\OAuthUserProvider
# arguments: [ @doctrine.orm.entity_manager, @session ]
#
# Custom Auth Handler (Only Event Listener).
......
......@@ -64,13 +64,13 @@
{% set flag = '' %}
{% set desc = '' %}
{% if tag.match == 100 %}
{% if tag.contextMatch == 100 %}
{% set flag = 'badge-important' %}
{% set desc = 'Sehr zutreffend' %}
{% elseif tag.match == 66 %}
{% elseif tag.contextMatch == 66 %}
{% set flag = 'badge-warning' %}
{% set desc = 'Trifft zu' %}
{% elseif tag.match == 33 %}
{% elseif tag.contextMatch == 33 %}
{% set flag = 'badge-inverse' %}
{% set desc = 'Trifft entfernt zu' %}
{% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment