Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Services;
use App\Entity\Parts\Part;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* A service related for searching for tags. Mostly useful for autocomplete reasons.
* @package App\Services
*/
class TagFinder
{
@ -45,20 +42,22 @@ class TagFinder
$resolver->setDefaults([
'query_limit' => 75,
'return_limit' => 25,
'min_keyword_length' => 3
'min_keyword_length' => 3,
]);
}
/**
* Search tags that begins with the certain keyword.
*
* @param string $keyword The keyword the tag must begin with
* @param array $options Some options specifying the search behavior. See configureOptions for possible options.
* @param array $options Some options specifying the search behavior. See configureOptions for possible options.
*
* @return string[] An array containing the tags that match the given keyword.
*/
public function searchTags(string $keyword, array $options = [])
{
$results = [];
$keyword_regex = '/^' . preg_quote($keyword, '/') . '/';
$keyword_regex = '/^'.preg_quote($keyword, '/').'/';
$resolver = new OptionsResolver();
$this->configureOptions($resolver);
@ -75,10 +74,10 @@ class TagFinder
$qb->select('p.tags')
->from(Part::class, 'p')
->where("p.tags LIKE ?1")
->where('p.tags LIKE ?1')
->setMaxResults($options['query_limit'])
//->orderBy('RAND()')
->setParameter(1, '%' . $keyword . '%');
->setParameter(1, '%'.$keyword.'%');
$possible_tags = $qb->getQuery()->getArrayResult();
@ -90,6 +89,6 @@ class TagFinder
$results = array_unique($results);
//Limit the returned tag count to specified value.
return array_slice($results, 0, $options['return_limit']);
return \array_slice($results, 0, $options['return_limit']);
}
}
}