Skip to content

Commit

Permalink
Code cleanup [SLE-192]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed May 8, 2024
1 parent 4927563 commit 90c7de1
Show file tree
Hide file tree
Showing 58 changed files with 202 additions and 460 deletions.
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# Slim Example Project

[![Latest Version on Packagist](https://img.shields.io/github/release/samuelgfeller/slim-example-project.svg)](https://packagist.org/packages/samuelgfeller/slim-example-project)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=samuelgfeller_slim-example-project&metric=coverage)](https://sonarcloud.io/summary/new_code?id=samuelgfeller_slim-example-project)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=samuelgfeller_slim-example-project&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=samuelgfeller_slim-example-project)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=samuelgfeller_slim-example-project&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=samuelgfeller_slim-example-project)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=samuelgfeller_slim-example-project&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=samuelgfeller_slim-example-project)
[![Code Coverage](https://scrutinizer-ci.com/g/samuelgfeller/slim-example-project/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/samuelgfeller/slim-example-project/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/samuelgfeller/slim-example-project/badges/build.png?b=master)](https://scrutinizer-ci.com/g/samuelgfeller/slim-example-project/build-status/master)
[![Quality Score](https://img.shields.io/scrutinizer/quality/g/samuelgfeller/slim-example-project.svg)](https://scrutinizer-ci.com/g/samuelgfeller/slim-example-project/?branch=master)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)

This project aims to be a real-world example of a modern [Slim 4](https://www.slimframework.com/)
web application with a scalable structure and
a range of practical components and features.
Real-world example of a modern [Slim 4](https://www.slimframework.com/) web application with a scalable
structure and a variety of components and features to get started quickly.

It showcases the implementation of a simple yet robust
This project showcases the implementation of a simple yet robust
[architecture](https://github.com/samuelgfeller/slim-example-project/wiki/Architecture)
with a variety of backend and
frontend features built using the Slim 4 micro-framework.
The base for this project was the official
[Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton) and Odan's [slim4-skeleton](https://github.com/odan/slim4-skeleton).

This repository can serve as a learning example or be adapted for developing new
applications.

External library dependencies are [kept to a minimum](https://github.com/samuelgfeller/slim-example-project/wiki/Libraries-and-Framework)
to facilitate maintenance and ensure long-term viability.

Expand All @@ -34,8 +30,8 @@ to get started.

Stripped down versions of this repository are available as skeleton
templates.
With frontend [`slim-starter`](https://github.com/samuelgfeller/slim-starter) or just for an API:
[`slim-api-starter`](https://github.com/samuelgfeller/slim-api-starter).
With frontend [slim-starter](https://github.com/samuelgfeller/slim-starter) or just for an API:
[slim-api-starter](https://github.com/samuelgfeller/slim-api-starter).

## Features
All the features were developed with an effort to ensure maximum user-friendliness.
Expand Down
14 changes: 9 additions & 5 deletions src/Domain/Client/Data/ClientData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(?array $clientData = [])
$this->id = $clientData['id'] ?? null;
$this->firstName = $clientData['first_name'] ?? null;
$this->lastName = $clientData['last_name'] ?? null;
$this->birthdate = isset($clientData['birthdate']) ? new \DateTimeImmutable($clientData['birthdate']) : null;
$this->birthdate = $this->createDateTimeImmutableString($clientData['birthdate'] ?? null);
$this->location = $clientData['location'] ?? null;
$this->phone = $clientData['phone'] ?? null;
$this->email = $clientData['email'] ?? null;
Expand All @@ -45,15 +45,19 @@ public function __construct(?array $clientData = [])
// Cast to int if user id is set and not empty (null / empty string)
$this->userId = !empty($clientData['user_id']) ? (int)$clientData['user_id'] : null;
$this->clientStatusId = !empty($clientData['client_status_id']) ? (int)$clientData['client_status_id'] : null;
$this->updatedAt = $clientData['updated_at'] ?? null ? new \DateTimeImmutable($clientData['updated_at']) : null;
$this->createdAt = $clientData['created_at'] ?? null ? new \DateTimeImmutable($clientData['created_at']) : null;
$this->deletedAt = $clientData['deleted_at'] ?? null ? new \DateTimeImmutable($clientData['deleted_at']) : null;

$this->updatedAt = $this->createDateTimeImmutableString($clientData['updated_at'] ?? null);
$this->createdAt = $this->createDateTimeImmutableString($clientData['created_at'] ?? null);
$this->deletedAt = $this->createDateTimeImmutableString($clientData['deleted_at'] ?? null);
if ($this->birthdate) {
$this->age = (new \DateTime())->diff($this->birthdate)->y;
}
}

private function createDateTimeImmutableString(?string $date): ?\DateTimeImmutable
{
return isset($date) ? new \DateTimeImmutable($date) : null;
}

/**
* Returns all values of object as array for the database.
* The array keys should match with the database
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/UserActivity/Repository/UserActivityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function findUserActivities(int|array $userIds): array
/**
* Insert user activity in database.
*
* @param mixed $userActivityRow
* @param array $userActivityRow
*
* @return int lastInsertId
*/
public function insertUserActivity($userActivityRow): int
public function insertUserActivity(array $userActivityRow): int
{
return (int)$this->queryFactory->insertQueryWithData($userActivityRow)->into('user_activity')->execute()->lastInsertId();
}
Expand Down
1 change: 1 addition & 0 deletions src/Infrastructure/Service/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/**
* Mailer class with added method to get the html string from a template and added logging in the send() function.
* Test sender score: https://www.mail-tester.com/.
* Documentation: https://github.com/samuelgfeller/slim-example-project/wiki/Mailing
*/
final readonly class Mailer
{
Expand Down
1 change: 1 addition & 0 deletions templates/authentication/email/new-account.email.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Hello <?= html($userFullName) ?> <br>
<br>
Your account has been created. <br> <br>
<?php /** Sentence asserted at @see \App\Test\Integration\User\UserCreateActionTest::testUserSubmitCreateAuthorization() */?>
To verify that this email address belongs to you, please click on the following link: <br>
<b><a href="<?= $route->fullUrlFor($uri, 'register-verification', [], $queryParams) ?>">Verify account</a></b>.
<br><br>
Expand Down
2 changes: 1 addition & 1 deletion templates/authentication/login.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<?php
// fetch() includes another template into the current template
// fetch() includes another template in the current template
// Include template which contains HTML to include assets
echo $this->fetch(
'layout/assets.html.php',
Expand Down
6 changes: 3 additions & 3 deletions templates/authentication/reset-password.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ class="form" method="post" autocomplete="on">
<?= isset($validation['password2']) ?
'<strong class="err-msg">' . html($validation['password2'][0]) . '</strong>' : '' ?>
</div>
<?= /*In case passwords not match there may be a second error for password2 */
<?= /*In case passwords don't match, there may be a second error for password2 */
isset($validation['password2'][1]) ? '<strong class="err-msg">' . html($validation['password2'][1])
. '</strong>' : '' ?>
<a href="login" class="subdued-text content-below-input cursor-pointer"><?= __('Login') ?></a>

<input type="hidden" name="token" value="<?= html($token ?? '') ?>">
<input type="hidden" name="id" value="<?= html($id ?? '') ?>">
<input type="hidden" name="token" value="<?= html($token) ?>">
<input type="hidden" name="id" value="<?= html($id) ?>">
<input type="submit" id="password-reset-submit-btn" class="submit-btn" style="margin-top: 20px"
value="<?= __('Set new password') ?>">
<?= $this->fetch('layout/request-throttle.html.php') ?>
Expand Down
5 changes: 1 addition & 4 deletions templates/client/clients-list.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
* active: array{\App\Domain\FilterSetting\Data\FilterData[]},
* } client list filters
*
* @var $clientCreatePrivilege Privilege create or none
* @var $clientCreatePrivilege App\Domain\Authorization\Privilege create or none
*/

use App\Domain\Authorization\Privilege;

$this->setLayout('layout/layout.html.php');

$this->addAttribute('libs', ['fontawesome.css']);

// Define assets that should be included
// Populate variable $css for layout which then generates the HTML code to include assets
Expand Down
76 changes: 0 additions & 76 deletions templates/error/error-details.html.php

This file was deleted.

26 changes: 0 additions & 26 deletions templates/layout/layout.email.php

This file was deleted.

2 changes: 1 addition & 1 deletion templates/layout/layout.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</head>
<body>
<!-- "In terms of semantics, <div> is the best choice" as wrapper https://css-tricks.com/best-way-implement-wrapper-css -->
<!-- Wrapper should encompass entire body content as its height is 100vh -->
<!-- Wrapper should encompass entire body content as its height is 100dvh -->
<div id="wrapper">
<header>
<!-- Application name displayed on mobile -->
Expand Down
2 changes: 1 addition & 1 deletion templates/user/user-list.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
'assets/general/page-component/modal/form-modal.css',
'assets/general/page-component/skeleton-loader/skeleton-loader.css',
'assets/user/list/user-list-skeleton-loader.css',
// Page-specific css has to come last to overwrite other styles
'assets/user/list/user-list.css',
// user-list.css has to come last to overwrite other styles
]);
// Js files that import things from other js files
$this->addAttribute(
Expand Down
2 changes: 1 addition & 1 deletion templates/user/user-read.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
'assets/general/page-component/modal/form-modal.css',
'assets/general/dark-mode/dark-mode-toggle-switch.css',
'assets/general/page-component/contenteditable/contenteditable.css',
// Page-specific css has to come last to overwrite other styles
'assets/user/user.css',
// user.css has to come last to overwrite other styles
]);


Expand Down
10 changes: 0 additions & 10 deletions tests/Fixture/ClientFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,4 @@ class ClientFixture
'deleted_at' => null,
],
];

public function getRecords(): array
{
return $this->records;
}

public function getTable(): string
{
return $this->table;
}
}
10 changes: 0 additions & 10 deletions tests/Fixture/ClientStatusFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,4 @@ class ClientStatusFixture
'deleted_at' => null,
],
];

public function getTable(): string
{
return $this->table;
}

public function getRecords(): array
{
return $this->records;
}
}
10 changes: 0 additions & 10 deletions tests/Fixture/NoteFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,4 @@ class NoteFixture
'deleted_at' => null,
],
];

public function getTable(): string
{
return $this->table;
}

public function getRecords(): array
{
return $this->records;
}
}
10 changes: 0 additions & 10 deletions tests/Fixture/UserActivityFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,4 @@ class UserActivityFixture
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0',
],
];

public function getTable(): string
{
return $this->table;
}

public function getRecords(): array
{
return $this->records;
}
}
10 changes: 0 additions & 10 deletions tests/Fixture/UserFilterSettingFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,4 @@ class UserFilterSettingFixture
'module' => 'dashboard-panel',
],
];

public function getTable(): string
{
return $this->table;
}

public function getRecords(): array
{
return $this->records;
}
}
10 changes: 0 additions & 10 deletions tests/Fixture/UserFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,4 @@ class UserFixture
'deleted_at' => null,
],
];

public function getTable(): string
{
return $this->table;
}

public function getRecords(): array
{
return $this->records;
}
}
14 changes: 4 additions & 10 deletions tests/Fixture/UserRoleFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace App\Test\Fixture;

/**
* User roles are automatically inserted in the setup of all test
* functions using the database.
*/
class UserRoleFixture
{
// Table name
Expand Down Expand Up @@ -30,14 +34,4 @@ class UserRoleFixture
'hierarchy' => 4,
],
];

public function getTable(): string
{
return $this->table;
}

public function getRecords(): array
{
return $this->records;
}
}
Loading

0 comments on commit 90c7de1

Please sign in to comment.