Skip to content

Commit

Permalink
Update symfony and dependencies
Browse files Browse the repository at this point in the history
Improve rector refactoring :
- code quality
- rename param to match type
- rename property to match type
- needs for php 8.4
  • Loading branch information
nikrou committed Dec 14, 2024
1 parent 94f81ae commit 67427ba
Show file tree
Hide file tree
Showing 113 changed files with 919 additions and 1,103 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"guzzlehttp/guzzle": "^7.8",
"phpspec/prophecy-phpunit": "2.*",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3.21",
"rector/rector": "^1.0",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-doctrine": "^2.0",
"rector/rector": "2.*",
"symfony/browser-kit": "^7.0",
"symfony/css-selector": "^7.0",
"symfony/debug-bundle": "^7.0",
Expand Down
475 changes: 260 additions & 215 deletions composer.lock

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
parameters:
ignoreErrors:
# need refactoring
- message: '#Access to an undefined property object::\$template\.#'
path: src/Phyxo/MenuBar.php

# need refactoring
- message: '#Access to an undefined property object::\$min_size\.#'
path: src/Phyxo/Image/ImageStandardParams.php

# need refactoring
- message: '#Result of && is always false#'
path: src/DataMapper/AlbumMapper.php

- message: '#Empty array passed to foreach.#'
path: src/Controller/Admin/AdminRatingController.php

# No more ws functions ?
- message: '#.*#'
path: src/Phyxo/Functions/Ws/*.php

# Not yet used
- message: '#Trait App\\Controller\\CommentControllerTrait is used zero times and is not analysed.#'
path: src/Controller/CommentControllerTrait.php
11 changes: 7 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
__DIR__ . '/tests'
])

->withSkipPath(__DIR__ . '/src/Phyxo/Functions/Ws/')

->withImportNames()

->withAttributesSets(symfony: true, doctrine: true)

->withSets([
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::SYMFONY_CODE_QUALITY,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
LevelSetList::UP_TO_PHP_82,
LevelSetList::UP_TO_PHP_84,
DoctrineSetList::DOCTRINE_CODE_QUALITY
])

Expand All @@ -42,7 +45,7 @@

->withPreparedSets(
deadCode: true,
// codeQuality: true,
codeQuality: true,
// naming: true,
// privatization: true
privatization: true
);
6 changes: 3 additions & 3 deletions src/Command/AssetsInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$targetArg = rtrim($input->getArgument('target') ?? '', '/');
if (!$targetArg) {
if ($targetArg === '' || $targetArg === '0') {
$targetArg = $this->rootProjectDir . '/public';
}

Expand Down Expand Up @@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->newLine();

if ($rows) {
if ($rows !== []) {
$io->table(['', 'Theme', 'Method / Error'], $rows);
}

Expand All @@ -147,7 +147,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($copyUsed) {
$io->note('Some assets were installed via copy. If you make changes to these assets you have to run this command again.');
}
$io->success($rows ? 'All assets were successfully installed.' : 'No assets were provided by any themes.');
$io->success($rows !== [] ? 'All assets were successfully installed.' : 'No assets were provided by any themes.');
}

return (int) $exitCode;
Expand Down
6 changes: 2 additions & 4 deletions src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
if (!empty($_SERVER['DATABASE_URL'])) {
$this->db_params['dsn'] = $_SERVER['DATABASE_URL'];
$this->db_params['db_prefix'] = $input->getOption('db_prefix') ?: $this->prefix;
} else {
if (!$io->askQuestion(new ConfirmationQuestion("Install Phyxo using these settings?", true))) {
return Command::SUCCESS;
}
} elseif (!$io->askQuestion(new ConfirmationQuestion("Install Phyxo using these settings?", true))) {
return Command::SUCCESS;
}

try {
Expand Down
35 changes: 16 additions & 19 deletions src/Controller/Admin/AdminAlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AdminAlbumController extends AbstractController
{
private TranslatorInterface $translator;

protected function setTabsheet(int $album_id, string $section = 'properties', int $parent_id = null): TabSheet
protected function setTabsheet(int $album_id, string $section = 'properties', ?int $parent_id = null): TabSheet
{
$tabsheet = new TabSheet();
$tabsheet->add('properties', $this->translator->trans('Properties', [], 'admin'), $this->generateUrl('admin_album', ['album_id' => $album_id, 'parent_id' => $parent_id]), 'fa-pencil');
Expand Down Expand Up @@ -91,7 +91,7 @@ public function properties(
}

if ($conf['activate_comments']) {
$album->setCommentable($request->request->get('commentable') === 'true' ? true : false);
$album->setCommentable($request->request->get('commentable') === 'true');
$need_update = true;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ public function sort_order(
AlbumMapper $albumMapper,
ImageStandardParams $image_std_params,
TranslatorInterface $translator,
int $parent_id = null
?int $parent_id = null
): Response {
$tpl_params = [];
$this->translator = $translator;
Expand Down Expand Up @@ -250,11 +250,12 @@ public function sort_order(
$image_order_choice = $request->request->get('image_order_choice');
}

$image_order = null;
$image_order = '';
if ($image_order_choice === 'user_define') {
for ($i = 0; $i < 3; $i++) {
if ($request->request->get('image_order')[$i]) {
if (!empty($image_order)) {
/** @phpstan-ignore-next-line */
if ($request->request->get('image_order')[$i] !== '' && $request->request->get('image_order')[$i] !== '0') {
if ($image_order !== '') {
$image_order .= ',';
}
$image_order .= $request->request->get('image_order')[$i];
Expand Down Expand Up @@ -330,11 +331,7 @@ public function sort_order(

$image_order = explode(',', (string) $album->getImageOrder());
for ($i = 0; $i < 3; $i++) { // 3 fields
if (isset($image_order[$i])) {
$tpl_params['image_order'][] = $image_order[$i];
} else {
$tpl_params['image_order'][] = '';
}
$tpl_params['image_order'][] = $image_order[$i] ?? '';
}

$tpl_params['image_order_choice'] = $image_order_choice;
Expand All @@ -359,7 +356,7 @@ public function permissions(
UserRepository $userRepository,
GroupRepository $groupRepository,
ManagerRegistry $managerRegistry,
int $parent_id = null
?int $parent_id = null
): Response {
$tpl_params = [];
$this->translator = $translator;
Expand Down Expand Up @@ -447,7 +444,7 @@ public function permissions(
}

$user_granted_indirect_ids = [];
if (count($tpl_params['groups_selected']) > 0) {
if ($tpl_params['groups_selected'] !== []) {
$granted_groups = [];

foreach ($groupRepository->findBy(['id' => $tpl_params['groups_selected']]) as $group) {
Expand Down Expand Up @@ -511,7 +508,7 @@ public function notification(
GroupRepository $groupRepository,
ImageMapper $imageMapper,
TranslatorInterface $translator,
int $parent_id = null
?int $parent_id = null
): Response {
$tpl_params = [];
$this->translator = $translator;
Expand Down Expand Up @@ -552,7 +549,7 @@ public function notification(
$all_groups[$group->getId()] = $group->getName();
}

if (count($all_groups) === 0) {
if ($all_groups === []) {
$tpl_params['no_group_in_gallery'] = true;
} else {
if ($album->getStatus() === Album::STATUS_PRIVATE) {
Expand All @@ -561,14 +558,14 @@ public function notification(
$group_ids[] = $group->getId();
}

if (count($group_ids) === 0) {
if ($group_ids === []) {
$tpl_params['U_PERMISSIONS'] = $this->generateUrl('admin_album_permissions', ['album_id' => $album_id, 'parent_id' => $parent_id]);
}
} else {
$group_ids = array_keys($all_groups);
}

if (count($group_ids) > 0) {
if ($group_ids !== []) {
$tpl_params['group_mail_options'] = array_filter($all_groups, fn ($key) => in_array($key, $group_ids), ARRAY_FILTER_USE_KEY);
}
}
Expand All @@ -593,7 +590,7 @@ public function create(
UserMapper $userMapper,
UserInfosRepository $userInfosRepository,
TranslatorInterface $translator,
int $parent_id = null
?int $parent_id = null
): Response {
if ($request->isMethod('POST')) {
$album_name = $request->request->get('album_name');
Expand Down Expand Up @@ -625,7 +622,7 @@ public function create(
return $this->redirectToRoute('admin_albums', ['parent_id' => $parent_id]);
}

public function delete(int $album_id, AlbumMapper $albumMapper, ImageMapper $imageMapper, UserMapper $userMapper, TranslatorInterface $translator, int $parent_id = null): Response
public function delete(int $album_id, AlbumMapper $albumMapper, ImageMapper $imageMapper, UserMapper $userMapper, TranslatorInterface $translator, ?int $parent_id = null): Response
{
$albumMapper->deleteAlbums([$album_id]);

Expand Down
20 changes: 7 additions & 13 deletions src/Controller/Admin/AdminAlbumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use App\Entity\Album;
use App\Repository\AlbumRepository;
use App\Repository\ImageAlbumRepository;
use Phyxo\Conf;
use Phyxo\TabSheet\TabSheet;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -38,12 +37,11 @@ protected function setTabsheet(string $section = 'list'): TabSheet
}

public function list(
Conf $conf,
AlbumRepository $albumRepository,
CsrfTokenManagerInterface $csrfTokenManager,
TranslatorInterface $translator,
ImageAlbumRepository $imageAlbumRepository,
int $parent_id = null
?int $parent_id = null
): Response {
$tpl_params = [];
$this->translator = $translator;
Expand All @@ -67,7 +65,7 @@ public function list(
}

// get the albums containing images directly
if (count($albums) > 0) {
if ($albums !== []) {
$nb_photos_in = $imageAlbumRepository->countImagesByAlbum();

$all_albums = [];
Expand Down Expand Up @@ -131,7 +129,7 @@ public function list(
return $this->render('albums_list.html.twig', $tpl_params);
}

public function update(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, int $parent_id = null): Response
public function update(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, ?int $parent_id = null): Response
{
if ($request->isMethod('POST')) {
if ($request->request->get('submitManualOrder')) { // save manual category ordering
Expand Down Expand Up @@ -162,23 +160,19 @@ public function update(Request $request, AlbumRepository $albumRepository, Album
if (str_starts_with($order_by_field, 'date_')) {
$order_by_date = true;

$ref_dates = $albumMapper->getAlbumsRefDate($category_ids, $order_by_field, 'ASC' == $order_by_asc ? 'min' : 'max');
$ref_dates = $albumMapper->getAlbumsRefDate($category_ids, $order_by_field, 'ASC' === $order_by_asc ? 'min' : 'max');
}

foreach ($albumRepository->findBy(['id' => $category_ids]) as $album) {
if ($order_by_date) {
$sort[] = $ref_dates[$album->getId()];
} else {
$sort[] = $album->getName();
}
$sort[] = $order_by_date ? $ref_dates[$album->getId()] : $album->getName();

$categories[] = [
'id' => $album->getId(),
'id_uppercat' => $album->getParent()->getId(),
];
}

array_multisort($sort, SORT_REGULAR, 'ASC' == $order_by_asc ? SORT_ASC : SORT_DESC, $categories);
array_multisort($sort, SORT_REGULAR, 'ASC' === $order_by_asc ? SORT_ASC : SORT_DESC, $categories);

$albumMapper->saveAlbumsOrder($categories);
$this->addFlash('success', $translator->trans('Albums automatically sorted', [], 'admin'));
Expand All @@ -188,7 +182,7 @@ public function update(Request $request, AlbumRepository $albumRepository, Album
return $this->redirectToRoute('admin_albums', ['parent_id' => $parent_id]);
}

public function move(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, int $parent_id = null): Response
public function move(Request $request, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator, ?int $parent_id = null): Response
{
$tpl_params = [];
$this->translator = $translator;
Expand Down
Loading

0 comments on commit 67427ba

Please sign in to comment.