Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #299 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Apr 5, 2023
2 parents a049061 + 29fcc78 commit 9c3524d
Show file tree
Hide file tree
Showing 66 changed files with 382 additions and 224 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* custom messages have been restored when, at login, the user account has been banned or is not yet active. Improved all
tests related to the login code;
* improved admin view for users;
* added the `PriorityBadgeHelper`. This replaces the `priority-badge` template element;
* every user can view his last logins;
* little fixes for admin template elements;
* vertical alignment is used for admin interface tables.

### 2.31.6
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ parameters:
- '#^Parameter \#[12] \$callback of function array_(map|walk) expects \(?callable\([^\)]+\): mixed\)?(\|null)?, (array{[^}]+}|Closure\([^\)]+\))(: string)? given\.$#'
-
message: '#^Variable \$\w+ might not be defined\.$#'
path: templates/
paths:
- templates/email
- templates/layout/ajax
- templates/layout/email
- templates/layout/json
- templates/layout/rss
-
message: '#^Property MeTools\\TestSuite\\CommandTestCase::\$_(err|in) \(Cake\\Console\\TestSuite\\StubConsole(Input|Output)\) does not accept null\.$#'
path: tests/TestCase/Command
Expand Down
113 changes: 84 additions & 29 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<code>empty($this-&gt;Users)</code>
</TypeDoesNotContainType>
</file>
<file src="src/Controller/SystemsController.php">
<RedundantPropertyInitializationCheck occurrences="2">
<code>$this-&gt;ContactUsForm</code>
<code>new ContactUsForm()</code>
</RedundantPropertyInitializationCheck>
</file>
<file src="src/Controller/Traits/GetStartAndEndDateTrait.php">
<RedundantCast occurrences="2">
<code>(int)($day ?: 1)</code>
Expand All @@ -15,16 +21,31 @@
<code>1</code>
<code>1</code>
</RedundantCondition>
<TypeDoesNotContainType occurrences="11">
<code>$day</code>
<code>$day</code>
<code>$day</code>
<code>$month</code>
<code>$month</code>
<code>$month</code>
<code>$month</code>
<code>$year</code>
<code>$year</code>
<code>$year</code>
<code>$year</code>
</TypeDoesNotContainType>
</file>
<file src="src/Model/Table/PostsTable.php">
<TooManyTemplateParams occurrences="1">
<code>\Cake\Collection\CollectionInterface&lt;\MeCms\Model\Entity\Post&gt;</code>
</TooManyTemplateParams>
<file src="src/Form/ContactUsForm.php">
<RedundantPropertyInitializationCheck occurrences="2">
<code>$this-&gt;SpamDetector</code>
<code>new SpamDetector()</code>
</RedundantPropertyInitializationCheck>
</file>
<file src="src/Model/Table/Traits/GetPreviewsFromTextTrait.php">
<TooManyTemplateParams occurrences="1">
<code>\Cake\Collection\CollectionInterface&lt;array{url: string, width: int, height: int}&gt;</code>
</TooManyTemplateParams>
<file src="src/Model/Table/AppTable.php">
<RedundantPropertyInitializationCheck occurrences="2">
<code>$this-&gt;cache</code>
<code>''</code>
</RedundantPropertyInitializationCheck>
</file>
<file src="src/Policy/ControllerResolver.php">
<MoreSpecificImplementedParamType occurrences="1">
Expand All @@ -36,29 +57,58 @@
<code>parent::__construct($name, $data, $dataName)</code>
</InternalMethod>
</file>
<file src="templates/Admin/Pages/form.php">
<TooManyTemplateParams occurrences="1">
<code>$this-&gt;extend('MeCms./common/form');</code>
</TooManyTemplateParams>
</file>
<file src="templates/Admin/Posts/form.php">
<TooManyTemplateParams occurrences="1">
<code>$this-&gt;extend('MeCms./common/form');</code>
</TooManyTemplateParams>
<file src="templates/PagesCategories/index.php">
<UndefinedGlobalVariable occurrences="1">
<code>$categories</code>
</UndefinedGlobalVariable>
</file>
<file src="templates/PagesCategories/view.php">
<UndefinedGlobalVariable occurrences="4">
<code>$category</code>
<code>$category</code>
<code>$category</code>
<code>$category</code>
</UndefinedGlobalVariable>
</file>
<file src="templates/Posts/index_by_date.php">
<TypeDoesNotContainType occurrences="7">
<code>$day</code>
<code>$month</code>
<code>$month</code>
<code>$year</code>
<code>$year</code>
<code>$year</code>
<code>$year</code>
</TypeDoesNotContainType>
</file>
<file src="templates/Posts/view.php">
<TooManyTemplateParams occurrences="1">
<code>$this-&gt;extend('/common/view');</code>
</TooManyTemplateParams>
</file>
<file src="templates/cell/PostsTagsWidgets/popular_as_cloud.php">
<TooManyTemplateParams occurrences="1"/>
</file>
<file src="templates/cell/PostsWidgets/months_as_form.php">
<TooManyTemplateParams occurrences="1"/>
</file>
<file src="templates/cell/PostsWidgets/months_as_list.php">
<TooManyTemplateParams occurrences="1"/>
<UndefinedGlobalVariable occurrences="15">
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$post</code>
<code>$related</code>
<code>$related</code>
<code>$related</code>
<code>'post'</code>
</UndefinedGlobalVariable>
</file>
<file src="templates/PostsCategories/index.php">
<UndefinedGlobalVariable occurrences="1">
<code>$categories</code>
</UndefinedGlobalVariable>
</file>
<file src="templates/PostsTags/index.php">
<UndefinedGlobalVariable occurrences="1">
<code>$tags</code>
</UndefinedGlobalVariable>
</file>
<file src="tests/TestCase/Command/UsersCommandTest.php">
<UndefinedPropertyAssignment occurrences="1">
Expand All @@ -75,6 +125,11 @@
<code>new \stdClass()</code>
</InvalidArgument>
</file>
<file src="tests/TestCase/TestSuite/TestCaseTest.php">
<UndefinedThisPropertyFetch occurrences="1">
<code>$this-&gt;noExistingProperty</code>
</UndefinedThisPropertyFetch>
</file>
<file src="tests/TestCase/View/View/Admin/AppViewTest.php">
<TypeDoesNotContainType occurrences="1">
<code>empty($this-&gt;View)</code>
Expand Down
21 changes: 10 additions & 11 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
</projectFiles>

<issueHandlers>
<DuplicateArrayKey errorLevel="suppress" />

<InternalMethod>
<errorLevel type="suppress">
<directory name="tests/TestCase" />
Expand All @@ -36,19 +34,20 @@
</errorLevel>
</InvalidScope>

<RedundantPropertyInitializationCheck errorLevel="suppress" />
<RedundantPropertyInitializationCheck>
<errorLevel type="suppress">
<directory name="tests/TestCase" />
</errorLevel>
</RedundantPropertyInitializationCheck>

<TypeDoesNotContainType>
<UndefinedGlobalVariable>
<errorLevel type="suppress">
<file name="src/Controller/Traits/GetStartAndEndDateTrait.php" />
<file name="templates/Posts/index_by_date.php" />
<directory name="templates/email" />
</errorLevel>
</TypeDoesNotContainType>
</UndefinedGlobalVariable>

<DuplicateArrayKey errorLevel="suppress" />
<UndefinedConstant errorLevel="suppress" />
<UndefinedGlobalVariable errorLevel="suppress" />
<UndefinedMagicMethod errorLevel="suppress" />
<UndefinedMethod errorLevel="suppress" />
<UndefinedThisPropertyFetch errorLevel="suppress" />
<TooManyTemplateParams errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/Controller/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function changePassword()
*/
public function changePicture()
{
/** @var ?\Laminas\Diactoros\UploadedFile $UploadedFile */
/** @var \Laminas\Diactoros\UploadedFile|array|null $UploadedFile */
$UploadedFile = $this->getRequest()->getData('file');

if ($this->getRequest()->is(['patch', 'post', 'put']) && $UploadedFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Traits/GetStartAndEndDateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait GetStartAndEndDateTrait
* Gets start and end date as `FrozenTime` instances starting from a string.
* These can be used for a `where` condition to search for records based on a date.
* @param string $date Date as `today`, `yesterday`, `YYYY/MM/dd`, `YYYY/MM` or `YYYY`
* @return array Array with start and end date as `FrozenTime` instances
* @return \Cake\I18n\FrozenTime[] Array with start and end date
*/
protected function getStartAndEndDate(string $date): array
{
Expand Down
3 changes: 1 addition & 2 deletions src/Validation/AppValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
/**
* Application validator class.
*
* This class adds some common rules and provides some common methods for all
* validators.
* This class adds some common rules and provides some common methods for all validators.
*/
class AppValidator extends Validator
{
Expand Down
60 changes: 60 additions & 0 deletions src/View/Helper/PriorityBadgeHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);

/**
* This file is part of me-cms.
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Mirko Pagliai
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
* @since 2.31.7
*/

namespace MeCms\View\Helper;

use Cake\View\Helper;

/**
* PriorityBadge helper
* @property \MeTools\View\Helper\HtmlHelper $Html
*/
class PriorityBadgeHelper extends Helper
{
/**
* Helpers
* @var array
*/
public $helpers = ['MeTools.Html'];

/**
* Creates a "priority" badge
* @param int $priority Priority value
* @return string Html string
*/
public function badge(int $priority): string
{
switch ($priority) {
case '1':
[$priority, $class, $tooltip] = ['1', 'priority-verylow', __d('me_cms', 'Very low')];
break;
case '2':
[$priority, $class, $tooltip] = ['2', 'priority-low', __d('me_cms', 'Low')];
break;
case '4':
[$priority, $class, $tooltip] = ['4', 'priority-high', __d('me_cms', 'High')];
break;
case '5':
[$priority, $class, $tooltip] = ['5', 'priority-veryhigh', __d('me_cms', 'Very high')];
break;
default:
[$priority, $class, $tooltip] = ['3', 'priority-normal', __d('me_cms', 'Normal')];
break;
}

return $this->Html->badge($priority, compact('class', 'tooltip'));
}
}
2 changes: 2 additions & 0 deletions src/View/View/Admin/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/**
* Application view class for admin views
* @property \MeCms\View\Helper\MenuBuilderHelper $MenuBuilder
* @property \MeCms\View\Helper\PriorityBadgeHelper $PriorityBadge
*/
class AppView extends View
{
Expand All @@ -37,6 +38,7 @@ public function initialize(): void
{
parent::initialize();

$this->loadHelper('MeCms.PriorityBadge');
$this->loadHelper('MeCms.MenuBuilder');
}

Expand Down
3 changes: 2 additions & 1 deletion templates/Admin/Pages/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \Cake\Collection\Collection<string> $categories
* @var \Cake\ORM\ResultSet<\MeCms\Model\Entity\PagesCategory> $categories
* @var \MeCms\Model\Entity\Page $page
* @var \MeCms\View\View\Admin\AppView $this
* @var string $title
*/

$this->extend('MeCms./common/form');
$this->Library->ckeditor();
$this->Library->slugify();
Expand Down
5 changes: 3 additions & 2 deletions templates/Admin/Pages/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \MeCms\Model\Entity\Page[] $pages
* @var \Cake\ORM\ResultSet<\MeCms\Model\Entity\Page> $pages
* @var \MeCms\View\View\Admin\AppView $this
*/

$this->extend('MeCms./Admin/common/index');
$this->assign('title', I18N_PAGES);
$this->append('actions', $this->Html->button(
Expand Down Expand Up @@ -136,7 +137,7 @@
</td>

<td class="text-nowrap text-center align-middle">
<?= $this->element('admin/priority-badge', ['priority' => $page->get('priority')]) ?>
<?= $this->PriorityBadge->badge($page->get('priority')) ?>
</td>
<td class="text-nowrap text-center align-middle">
<div class="d-none d-lg-block">
Expand Down
3 changes: 3 additions & 0 deletions templates/Admin/PagesCategories/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
* @copyright Copyright (c) Mirko Pagliai
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \MeCms\View\View\Admin\AppView $this
*/

$this->extend('/Admin/PostsCategories/form');
2 changes: 1 addition & 1 deletion templates/Admin/PagesCategories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \MeCms\Model\Entity\PagesCategory[] $categories
* @var \Cake\ORM\ResultSet<\MeCms\Model\Entity\PagesCategory> $categories
* @var \MeCms\View\View\Admin\AppView $this
*/

Expand Down
3 changes: 2 additions & 1 deletion templates/Admin/Posts/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \Cake\Collection\Collection<string> $categories
* @var \Cake\ORM\ResultSet<\MeCms\Model\Entity\PostsCategory> $categories
* @var \MeCms\Model\Entity\Post $post
* @var \MeCms\View\View\Admin\AppView $this
* @var string $title
*/

$this->extend('MeCms./common/form');
$this->Library->ckeditor();
$this->Library->slugify();
Expand Down
4 changes: 2 additions & 2 deletions templates/Admin/Posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @link https://github.com/mirko-pagliai/me-cms
* @license https://opensource.org/licenses/mit-license.php MIT License
*
* @var \MeCms\Model\Entity\Post[] $posts
* @var \Cake\ORM\ResultSet<\MeCms\Model\Entity\Post> $posts
* @var \MeCms\View\View\Admin\AppView $this
*/

Expand Down Expand Up @@ -171,7 +171,7 @@
) ?>
</td>
<td class="text-nowrap text-center align-middle">
<?= $this->element('admin/priority-badge', ['priority' => $post->get('priority')]) ?>
<?= $this->PriorityBadge->badge($post->get('priority')) ?>
</td>
<td class="text-nowrap text-center align-middle">
<div class="d-none d-lg-block">
Expand Down
Loading

0 comments on commit 9c3524d

Please sign in to comment.