Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to PHP 8.2 #74

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ of the original MINI, made by [JaoNoctus](https://github.com/JaoNoctus). Big tha

## Requirements (but it's auto-installed)

- PHP 8
- PHP 8.2 and higher
- MySQL
- basic knowledge of Composer for sure
- for auto-installation: VirtualBox, Vagrant
Expand Down
2 changes: 1 addition & 1 deletion application/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ErrorController
* PAGE: index
* This method handles the error page that will be shown when a page is not found
*/
public function index()
public function index(): void
{
// load views
require APP . 'view/_templates/header.php';
Expand Down
6 changes: 3 additions & 3 deletions application/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HomeController
* PAGE: index
* This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
*/
public function index()
public function index(): void
{
// load views
require APP . 'view/_templates/header.php';
Expand All @@ -30,7 +30,7 @@ public function index()
* This method handles what happens when you move to http://yourproject/home/exampleone
* The camelCase writing is just for better readability. The method name is case-insensitive.
*/
public function exampleOne()
public function exampleOne(): void
{
// load views
require APP . 'view/_templates/header.php';
Expand All @@ -43,7 +43,7 @@ public function exampleOne()
* This method handles what happens when you move to http://yourproject/home/exampletwo
* The camelCase writing is just for better readability. The method name is case-insensitive.
*/
public function exampleTwo()
public function exampleTwo(): void
{
// load views
require APP . 'view/_templates/header.php';
Expand Down
16 changes: 8 additions & 8 deletions application/Controller/SongsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SongsController
* PAGE: index
* This method handles what happens when you move to http://yourproject/songs/index
*/
public function index()
public function index(): void
{
// Instance new Model (Song)
$Song = new Song();
Expand All @@ -44,7 +44,7 @@ public function index()
* the user back to songs/index via the last line: header(...)
* This is an example of how to handle a POST request.
*/
public function addSong()
public function addSong(): void
{
// if we have POST data to create a new song entry
if (isset($_POST["submit_add_song"])) {
Expand All @@ -65,9 +65,9 @@ public function addSong()
* directs the user after the click. This method handles all the data from the GET request (in the URL!) and then
* redirects the user back to songs/index via the last line: header(...)
* This is an example of how to handle a GET request.
* @param int $song_id Id of the to-delete song
* @param ?int $song_id Id of the to-delete song
*/
public function deleteSong($song_id)
public function deleteSong(?int $song_id): void
{
// if we have an id of a song that should be deleted
if (isset($song_id)) {
Expand All @@ -84,9 +84,9 @@ public function deleteSong($song_id)
/**
* ACTION: editSong
* This method handles what happens when you move to http://yourproject/songs/editsong
* @param int $song_id Id of the to-edit song
* @param ?int $song_id Id of the to-edit song
*/
public function editSong($song_id)
public function editSong(?int $song_id): void
{
// if we have an id of a song that should be edited
if (isset($song_id)) {
Expand Down Expand Up @@ -116,7 +116,7 @@ public function editSong($song_id)
* the user back to songs/index via the last line: header(...)
* This is an example of how to handle a POST request.
*/
public function updateSong()
public function updateSong(): void
{
// if we have POST data to create a new song entry
if (isset($_POST["submit_update_song"])) {
Expand All @@ -134,7 +134,7 @@ public function updateSong()
* AJAX-ACTION: ajaxGetStats
* TODO documentation
*/
public function ajaxGetStats()
public function ajaxGetStats(): void
{
// Instance new Model (Song)
$Song = new Song();
Expand Down
16 changes: 8 additions & 8 deletions application/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

class Application
{
/** @var null The controller */
private $url_controller = null;
/** @var ?object The controller */
private ?object $url_controller = null;

/** @var null The method (of the above controller), often also named "action" */
private $url_action = null;
/** @var ?string The method (of the above controller), often also named "action" */
private ?string $url_action = null;

/** @var array URL parameters */
private $url_params = array();
private array $url_params = [];

/**
* "Start" the application:
Expand Down Expand Up @@ -63,7 +63,7 @@ public function __construct()
/**
* Get and split the URL
*/
private function splitUrl()
private function splitUrl(): void
{
if (isset($_GET['url'])) {

Expand All @@ -75,8 +75,8 @@ private function splitUrl()
// Put URL parts into according properties
// By the way, the syntax here is just a short form of if/else, called "Ternary Operators"
// @see http://davidwalsh.name/php-shorthand-if-else-ternary-operators
$this->url_controller = isset($url[0]) ? $url[0] : null;
$this->url_action = isset($url[1]) ? $url[1] : null;
$this->url_controller = $url[0] ?? null;
$this->url_action = $url[1] ?? null;

// Remove controller and action from the split URL
unset($url[0], $url[1]);
Expand Down
6 changes: 3 additions & 3 deletions application/Core/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class Model
{
/**
* @var null Database Connection
* @var ?PDO Database Connection
*/
public $db = null;
public ?PDO $db = null;

/**
* Whenever model is created, open a database connection.
Expand All @@ -26,7 +26,7 @@ function __construct()
/**
* Open the database connection with the credentials from application/config/config.php
*/
private function openDatabaseConnection()
private function openDatabaseConnection(): void
{
// set the (optional) options of the PDO connection. in this case, we set the fetch mode to
// "objects", which means all results will be objects, like this: $result->user_name !
Expand Down
12 changes: 6 additions & 6 deletions application/Model/Song.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Song extends Model
/**
* Get all songs from database
*/
public function getAllSongs()
public function getAllSongs(): false|array
{
$sql = "SELECT id, artist, track, link FROM song";
$query = $this->db->prepare($sql);
Expand All @@ -43,7 +43,7 @@ public function getAllSongs()
* @param string $track Track
* @param string $link Link
*/
public function addSong($artist, $track, $link)
public function addSong(string $artist, string $track, string $link): void
{
$sql = "INSERT INTO song (artist, track, link) VALUES (:artist, :track, :link)";
$query = $this->db->prepare($sql);
Expand All @@ -61,7 +61,7 @@ public function addSong($artist, $track, $link)
* add/update/delete stuff!
* @param int $song_id Id of song
*/
public function deleteSong($song_id)
public function deleteSong(int $song_id): void
{
$sql = "DELETE FROM song WHERE id = :song_id";
$query = $this->db->prepare($sql);
Expand All @@ -77,7 +77,7 @@ public function deleteSong($song_id)
* Get a song from database
* @param integer $song_id
*/
public function getSong($song_id)
public function getSong(int $song_id): mixed
{
$sql = "SELECT id, artist, track, link FROM song WHERE id = :song_id LIMIT 1";
$query = $this->db->prepare($sql);
Expand All @@ -104,7 +104,7 @@ public function getSong($song_id)
* @param string $link Link
* @param int $song_id Id
*/
public function updateSong($artist, $track, $link, $song_id)
public function updateSong(string $artist, string $track, string $link, int $song_id): void
{
$sql = "UPDATE song SET artist = :artist, track = :track, link = :link WHERE id = :song_id";
$query = $this->db->prepare($sql);
Expand All @@ -120,7 +120,7 @@ public function updateSong($artist, $track, $link, $song_id)
* Get simple "stats". This is just a simple demo to show
* how to use more than one model in a controller (see application/controller/songs.php for more)
*/
public function getAmountOfSongs()
public function getAmountOfSongs(): ?int
{
$sql = "SELECT COUNT(id) AS amount_of_songs FROM song";
$query = $this->db->prepare($sql);
Expand Down
4 changes: 2 additions & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sudo apt-get update
sudo apt-get -y upgrade

# php
sudo apt install -y php8.1-fpm
sudo apt install -y php8.2-fpm
# php modules
sudo apt install -y php-xml
sudo apt install -y php-mbstring
Expand All @@ -25,7 +25,7 @@ sudo systemctl restart nginx
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD"
sudo apt-get install -y mysql-server
sudo apt-get install -y php8.1-mysql
sudo apt-get install -y php8.2-mysql

# run SQL statements
sudo mysql -h "localhost" -u "root" "-p${PASSWORD}" < "/var/www/html/_install/mysql/01-create-database.sql"
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "panique/mini3",
"minimum-stability": "dev",
"require": {},
"require": {
"php": ">=8.2"
},
"autoload":
{
"psr-4":
Expand Down