Skip to content

Commit

Permalink
do refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Митрофанов Николай committed Apr 25, 2017
1 parent 2f30797 commit 079ffdf
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 189 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/node_modules/
*.log
.idea
*.iml
*.iml
/vendor
composer.lock
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class AppKernel extends Kernel
}
```

### Конфигурируем роутинг

```yml
# app/config/routing.yml
...
fod_query_constructor:
resource: "@QueryConstructorBundle/Controller/DefaultController.php"
type: annotation
prefix: /fod

```

### Рендер формы конструктора

В папке `/assets` пакета содержатся готовые скомпилированные js-файлы.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"keywords": ["doctrine"],
"type": "library",
"require": {
"doctrine/orm": "^2.5"
"symfony/symfony": "^2.8",
"doctrine/orm": "^2.5",
"sensio/framework-extra-bundle": "^3.0"
},
"license": "MIT",
"autoload": {
Expand Down
9 changes: 6 additions & 3 deletions src/Bundle/Twig/QueryConstructorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ class QueryConstructorExtension extends \Twig_Extension
public function getFunctions()
{
return [
'fod_query_constructor' => new \Twig_Function_Method(
$this,
'render',
'fod_query_constructor' => new \Twig_SimpleFunction(
'fod_query_constructor',
[$this, 'render'],
['needs_environment' => true]
),
];
}

/**
* @param \Twig_Environment $environment
* @param array $options
* @param string $template
* @return string
*/
public function render(\Twig_Environment $environment, $options = [], $template = 'QueryConstructorBundle::default.html.twig')
{
Expand Down
6 changes: 3 additions & 3 deletions src/Creator/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Creator

/**
* @param EntityManagerInterface $em
* @param ProviderRegistry $registry
* @param Registry $registry
*/
public function __construct(EntityManagerInterface $em, Registry $registry)
{
Expand Down Expand Up @@ -96,12 +96,12 @@ public function createFromJson($value, \DateTime $dateReport = null)
QueryCondition::OPERATOR_TYPE_MORE_THAN_OR_EQUALS,
];

if (is_null($doc)) {
if (null === $doc) {
throw new CreatorException('Expected valid json document.');
}

if (!isset($doc['aggregateFunction'])
|| !in_array($doc['aggregateFunction'], $this->getAggregateFunctions())) {
|| !in_array($doc['aggregateFunction'], $this->getAggregateFunctions(), true)) {
throw new CreatorException(sprintf(
'Document must contain property "aggregateFunction" with one of this values: %s.',
implode($this->getAggregateFunctions(), ',')
Expand Down
4 changes: 2 additions & 2 deletions src/Creator/Joiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Joiner
protected $baseEntityMetadataProvider;

/**
* @var EntityManagerInterfaceInterface
* @var EntityManagerInterface
*/
protected $em;

Expand Down Expand Up @@ -182,6 +182,6 @@ protected function makeJoin(
*/
protected function alreadyJoined(QueryBuilder $qb, $entityAlias)
{
return in_array($entityAlias, $qb->getAllAliases());
return in_array($entityAlias, $qb->getAllAliases(), true);
}
}
4 changes: 2 additions & 2 deletions src/Creator/QueryCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
self::CONDITION_TYPE_AND,
self::CONDITION_TYPE_OR,
self::CONDITION_TYPE_NONE
])) {
], true)) {
throw new CreatorException(sprintf('Bad condition type given: %s', $type));
}

Expand All @@ -73,7 +73,7 @@ public function __construct(
self::OPERATOR_TYPE_NOT_IN,
self::OPERATOR_TYPE_LIKE,
self::OPERATOR_TYPE_NOT_LIKE,
])) {
], true)) {
throw new CreatorException(sprintf('Bad condition operator given: %s', $operator));
}

Expand Down
148 changes: 0 additions & 148 deletions src/DBALTranslator/DBALTranslator.php

This file was deleted.

7 changes: 2 additions & 5 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ public function setJoins(array $joins)
protected function getClassBaseName($className)
{
$lastNamespacePos = strrpos($className, '\\');
if ($lastNamespacePos === false) {
return $className;
} else {
return substr($className, $lastNamespacePos + 1);
}

return false === $lastNamespacePos ? $className : substr($className, $lastNamespacePos + 1);
}
}
24 changes: 8 additions & 16 deletions src/Mapping/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ protected function filterOnlyExcept(array $properties, array $only, array $excep
*/
protected function filterOnly(array $properties, array $names = null)
{
if ($names) {
return array_filter($properties, function (\ReflectionProperty $property) use ($names) {
return in_array($property->getName(), $names);
});
} else {
return $properties;
}
return $names ? array_filter($properties, function (\ReflectionProperty $property) use ($names) {
return in_array($property->getName(), $names, true);
}) : $properties;
}

/**
Expand All @@ -107,13 +103,9 @@ protected function filterOnly(array $properties, array $names = null)
*/
protected function filterExcept(array $properties, array $names = null)
{
if ($names) {
return array_filter($properties, function (\ReflectionProperty $property) use ($names) {
return !in_array($property->getName(), $names);
});
} else {
return $properties;
}
return $names ? array_filter($properties, function (\ReflectionProperty $property) use ($names) {
return !in_array($property->getName(), $names, true);
}) : $properties;
}

/**
Expand Down Expand Up @@ -193,7 +185,7 @@ protected function detectListFields(OrmClassMetadata $metadata, $propertyName, $
if ($fieldName === $valueField) {
continue;
}
if (in_array($referencedMetadata->getTypeOfField($fieldName), [Type::STRING, Type::TEXT])) {
if (in_array($referencedMetadata->getTypeOfField($fieldName), [Type::STRING, Type::TEXT], true)) {
$titleField = $fieldName;
break;
}
Expand Down Expand Up @@ -258,7 +250,7 @@ protected function mapPropertyTypeFromDoctrine($propertyType)
*/
protected function getAssociations(OrmClassMetadata $metadata)
{
if (is_null($this->associations)) {
if (null === $this->associations) {
$this->associations = [];
foreach ($metadata->getAssociationMappings() as $field => $mapping) {
if (!$mapping['isOwningSide']) {
Expand Down
4 changes: 3 additions & 1 deletion src/Metadata/DoctrineDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Common\Annotations\Reader as AnnotationReader;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;
use FOD\QueryConstructor\Mapping\Reader;

/**
Expand Down Expand Up @@ -53,11 +54,12 @@ public function discoverAll()

/**
* @param string $className
* @return FOD\QueryConstructor\Mapping\ClassMetadata
* @return \FOD\QueryConstructor\Mapping\ClassMetadata
*/
public function getClassMetaData($className)
{
$ormClassMetadata = $this->em->getMetadataFactory()->getMetadataFor($className);

return $this->reader->getClassMetaData($ormClassMetadata);
}
}
14 changes: 7 additions & 7 deletions src/Serializer/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public function getValue($name)
{
if ($accessor = $this->getPublicProperty($name)) {
return $this->object->{$accessor};
} elseif ($accessor = $this->getFirstPublicMethod($name, ['get', 'is', 'has'])) {
}
if ($accessor = $this->getFirstPublicMethod($name, ['get', 'is', 'has'])) {
return $this->object->{$accessor}();
} else {
throw new \BadMethodCallException(sprintf(
'Class "%s" has neither property nor accessor "%s"',
get_class($this->object),
$name
));
}
throw new \BadMethodCallException(sprintf(
'Class "%s" has neither property nor accessor "%s"',
get_class($this->object),
$name
));
}

/**
Expand Down

0 comments on commit 079ffdf

Please sign in to comment.