type signatures a la 7.1

This commit is contained in:
flash 2016-12-04 17:33:52 +01:00
parent 5607ef7c55
commit 3b60cf457e
76 changed files with 407 additions and 462 deletions

View file

@ -19,7 +19,7 @@ class ActionCode
* @param int $user * @param int $user
* @return string * @return string
*/ */
public static function generate($action, $user = 0) public static function generate(string $action, int $user = 0): string
{ {
// Generate a code // Generate a code
$code = uniqid(); $code = uniqid();
@ -44,7 +44,7 @@ class ActionCode
* @param bool $invalidate * @param bool $invalidate
* @return bool * @return bool
*/ */
public static function validate($action, $code, $user = 0, $invalidate = true) public static function validate(string $action, string $code, int $user = 0, bool $invalidate = true): bool
{ {
// Fetch the code from the db // Fetch the code from the db
$get = DB::table('actioncodes') $get = DB::table('actioncodes')
@ -66,7 +66,7 @@ class ActionCode
* Make a code invalid. * Make a code invalid.
* @param string $code * @param string $code
*/ */
public static function invalidate($code) public static function invalidate(string $code): void
{ {
DB::table('actioncodes') DB::table('actioncodes')
->where('action_code', $code) ->where('action_code', $code)

View file

@ -58,15 +58,14 @@ class Parser
/** /**
* Parse the emoticons. * Parse the emoticons.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parseEmoticons($text, User $poster = null) public static function parseEmoticons(string $text, User $poster = null): string
{ {
// Get emoticons from the database
$emotes = DB::table('emoticons') $emotes = DB::table('emoticons')
->get(); ->get();
// Parse all emoticons
foreach ($emotes as $emote) { foreach ($emotes as $emote) {
if ($poster === null) { if ($poster === null) {
// eventually check for hierarchies here // eventually check for hierarchies here
@ -78,16 +77,16 @@ class Parser
$text = preg_replace("#{$icon}#", $image, $text); $text = preg_replace("#{$icon}#", $image, $text);
} }
// Return the parsed text
return $text; return $text;
} }
/** /**
* Convert the parsed text to HTML. * Convert the parsed text to HTML.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function toHTML($text, User $poster) public static function toHTML(string $text, User $poster): string
{ {
$text = self::parseEmoticons($text); $text = self::parseEmoticons($text);

View file

@ -30,9 +30,10 @@ class TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace(static::$pattern, static::$replace, $text); return preg_replace(static::$pattern, static::$replace, $text);
} }

View file

@ -19,9 +19,10 @@ class Align extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[align\=(left|center|centre|right)\](.*?)\[\/align\]/s', '/\[align\=(left|center|centre|right)\](.*?)\[\/align\]/s',

View file

@ -19,9 +19,10 @@ class Box extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[box(?:\=(.*?))?\](.*?)\[\/box\]/s', '/\[box(?:\=(.*?))?\](.*?)\[\/box\]/s',

View file

@ -19,9 +19,10 @@ class Code extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[code(?:\=([a-z]+))?\](.*?)\[\/code\]/s', '/\[code(?:\=([a-z]+))?\](.*?)\[\/code\]/s',

View file

@ -19,9 +19,10 @@ class ListTag extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[list(?:\=(1|A|a|I|i))?\](.*?)\[\/list\]/s', '/\[list(?:\=(1|A|a|I|i))?\](.*?)\[\/list\]/s',

View file

@ -26,9 +26,10 @@ class Markdown extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[md\](.*?)\[\/md\]/s', '/\[md\](.*?)\[\/md\]/s',

View file

@ -21,9 +21,10 @@ class NamedQuote extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[quote\=(#?)(.*?)\](.*)\[\/quote\]/s', '/\[quote\=(#?)(.*?)\](.*)\[\/quote\]/s',

View file

@ -43,9 +43,10 @@ class Size extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[size\=([a-z0-9]+)\](.*?)\[\/size\]/s', '/\[size\=([a-z0-9]+)\](.*?)\[\/size\]/s',

View file

@ -19,9 +19,10 @@ class UserTag extends TagBase
/** /**
* Parses the bbcode. * Parses the bbcode.
* @param string $text * @param string $text
* @param User $poster
* @return string * @return string
*/ */
public static function parse($text, User $poster) public static function parse(string $text, User $poster): string
{ {
return preg_replace_callback( return preg_replace_callback(
'/\[user\]([0-9]+)\[\/user\]/s', '/\[user\]([0-9]+)\[\/user\]/s',

View file

@ -248,7 +248,7 @@ class Settings
/** /**
* Applies settings based on Sakura's configuration. * Applies settings based on Sakura's configuration.
*/ */
public function loadStandard() public function loadStandard(): void
{ {
$this->protocol = config('chat.protocol'); $this->protocol = config('chat.protocol');
$this->server = config('chat.server'); $this->server = config('chat.server');
@ -278,7 +278,7 @@ class Settings
* @param int $hierarchy * @param int $hierarchy
* @param bool $relativePath * @param bool $relativePath
*/ */
public function addEmoticon($triggers, $image, $hierarchy = 0, $relativePath = false) public function addEmoticon(array $triggers, string $image, int $hierarchy = 0, bool $relativePath = false): void
{ {
$this->emoticons[] = [ $this->emoticons[] = [
'Text' => $triggers, 'Text' => $triggers,

View file

@ -25,7 +25,7 @@ class URLResolver
* @param string $hash * @param string $hash
* @return LinkInfo * @return LinkInfo
*/ */
public static function resolve($protocol, $slashes, $authority, $host, $port, $path, $query, $hash) public static function resolve(string $protocol, string $slashes, string $authority, string $host, string $port, string $path, string $query, string $hash): LinkInfo
{ {
$url = "{$protocol}:{$slashes}{$authority}{$host}{$port}{$path}{$query}{$hash}"; $url = "{$protocol}:{$slashes}{$authority}{$host}{$port}{$path}{$query}{$hash}";
$info = new LinkInfo; $info = new LinkInfo;

View file

@ -77,7 +77,7 @@ class Comment
* Constructor. * Constructor.
* @var int $id * @var int $id
*/ */
public function __construct($id = 0) public function __construct(int $id = 0)
{ {
// Get comment data from the database // Get comment data from the database
$data = DB::table('comments') $data = DB::table('comments')
@ -100,7 +100,7 @@ class Comment
/** /**
* Saving changes made to this comment. * Saving changes made to this comment.
*/ */
public function save() public function save(): void
{ {
// Create submission data, insert and update take the same format // Create submission data, insert and update take the same format
$data = [ $data = [
@ -125,7 +125,7 @@ class Comment
/** /**
* Delete this comment. * Delete this comment.
*/ */
public function delete() public function delete(): void
{ {
foreach ($this->replies() as $reply) { foreach ($this->replies() as $reply) {
$reply->delete(); $reply->delete();
@ -141,7 +141,7 @@ class Comment
/** /**
* Gets and caches the upvotes. * Gets and caches the upvotes.
*/ */
private function getVotes() private function getVotes(): void
{ {
$this->upvotes = intval(DB::table('comment_votes') $this->upvotes = intval(DB::table('comment_votes')
->where('vote_comment', $this->id) ->where('vote_comment', $this->id)
@ -157,7 +157,7 @@ class Comment
* Gets the parsed comment text * Gets the parsed comment text
* @return string * @return string
*/ */
public function parsed() public function parsed(): string
{ {
if (!$this->parsedCache) { if (!$this->parsedCache) {
$this->parsedCache = BBCode\Parser::parseEmoticons(clean_string($this->text)); $this->parsedCache = BBCode\Parser::parseEmoticons(clean_string($this->text));
@ -170,7 +170,7 @@ class Comment
* Get the replies to this comment. * Get the replies to this comment.
* @return array * @return array
*/ */
public function replies() public function replies(): array
{ {
if (!$this->replyCache) { if (!$this->replyCache) {
$commentIds = DB::table('comments') $commentIds = DB::table('comments')
@ -191,7 +191,7 @@ class Comment
* Gets the user object of the poster. * Gets the user object of the poster.
* @return User * @return User
*/ */
public function userData() public function userData(): User
{ {
return User::construct($this->user); return User::construct($this->user);
} }
@ -201,7 +201,7 @@ class Comment
* @param int $user * @param int $user
* @param bool $vote * @param bool $vote
*/ */
public function vote($user, $vote) public function vote(int $user, bool $vote): void
{ {
$vote = $vote ? '1' : '0'; $vote = $vote ? '1' : '0';

View file

@ -29,7 +29,7 @@ class Config
* @throws ConfigParseException * @throws ConfigParseException
* @param string $path * @param string $path
*/ */
public static function load($path) public static function load(string $path): void
{ {
// Check if the configuration file exists // Check if the configuration file exists
if (!file_exists($path)) { if (!file_exists($path)) {
@ -53,7 +53,7 @@ class Config
* @throws ConfigValueNotFoundException * @throws ConfigValueNotFoundException
* @return array|string * @return array|string
*/ */
public static function get($section, $key = null) public static function get(string $section, string $key = null)
{ {
// Check if the key that we're looking for exists // Check if the key that we're looking for exists
if (array_key_exists($section, self::$config)) { if (array_key_exists($section, self::$config)) {

View file

@ -6,22 +6,24 @@
namespace Sakura\Console; namespace Sakura\Console;
use CLIFramework\Application as CLIApp;
/** /**
* Command line interface main. * Command line interface main.
* @package Sakura * @package Sakura
* @author Julian van de Groep <me@flash.moe> * @author Julian van de Groep <me@flash.moe>
*/ */
class Application extends \CLIFramework\Application class Application extends CLIApp
{ {
/** /**
* CLI Application name. * CLI Application name.
*/ */
const NAME = 'Sakura'; public const NAME = 'Sakura';
/** /**
* CLI Application version. * CLI Application version.
*/ */
const VERSION = 9001; public const VERSION = 9001;
/** /**
* Enable command autoloading. * Enable command autoloading.

View file

@ -22,7 +22,7 @@ class DatabaseInstallCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Create the migration repository'; return 'Create the migration repository';
} }
@ -30,7 +30,7 @@ class DatabaseInstallCommand extends Command
/** /**
* Does the repository installing. * Does the repository installing.
*/ */
public function execute() public function execute(): void
{ {
$repository = DB::getMigrationRepository(); $repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem); $migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);

View file

@ -21,13 +21,13 @@ class DatabaseMigrateCommand extends Command
/** /**
* The database migrations directory. * The database migrations directory.
*/ */
const MIGRATIONS = "database/"; private const MIGRATIONS = "database/";
/** /**
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Run the database migrations'; return 'Run the database migrations';
} }
@ -35,7 +35,7 @@ class DatabaseMigrateCommand extends Command
/** /**
* Does the migrating. * Does the migrating.
*/ */
public function execute() public function execute(): void
{ {
$repository = DB::getMigrationRepository(); $repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem); $migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);

View file

@ -22,7 +22,7 @@ class DatabaseResetCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Rollback all database migrations'; return 'Rollback all database migrations';
} }
@ -30,7 +30,7 @@ class DatabaseResetCommand extends Command
/** /**
* Does the resetting. * Does the resetting.
*/ */
public function execute() public function execute(): void
{ {
$repository = DB::getMigrationRepository(); $repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem); $migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);

View file

@ -22,7 +22,7 @@ class DatabaseRollbackCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Rollback the last database migration'; return 'Rollback the last database migration';
} }
@ -30,7 +30,7 @@ class DatabaseRollbackCommand extends Command
/** /**
* Does the rolling back. * Does the rolling back.
*/ */
public function execute() public function execute(): void
{ {
$repository = DB::getMigrationRepository(); $repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem); $migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);

View file

@ -22,13 +22,13 @@ class DatabaseStatusCommand extends Command
/** /**
* The database migrations directory. * The database migrations directory.
*/ */
const MIGRATIONS = "database/"; private const MIGRATIONS = "database/";
/** /**
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Show the status of each migration'; return 'Show the status of each migration';
} }
@ -36,7 +36,7 @@ class DatabaseStatusCommand extends Command
/** /**
* Fulfills the purpose of what is described above this class. * Fulfills the purpose of what is described above this class.
*/ */
public function execute() public function execute(): void
{ {
$repository = DB::getMigrationRepository(); $repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem); $migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);

View file

@ -21,7 +21,7 @@ class PremiumPurgeCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Purge expired premium.'; return 'Purge expired premium.';
} }
@ -29,7 +29,7 @@ class PremiumPurgeCommand extends Command
/** /**
* Purge expired premium subs. * Purge expired premium subs.
*/ */
public function execute() public function execute(): void
{ {
$expiredPremium = DB::table('premium') $expiredPremium = DB::table('premium')
->where('premium_expire', '<', time()) ->where('premium_expire', '<', time())

View file

@ -21,7 +21,7 @@ class RebuildForumCacheCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Rebuild the forum bbcode cache'; return 'Rebuild the forum bbcode cache';
} }
@ -29,7 +29,7 @@ class RebuildForumCacheCommand extends Command
/** /**
* Does the repository installing. * Does the repository installing.
*/ */
public function execute() public function execute(): void
{ {
$this->getLogger()->writeln("This might take a while..."); $this->getLogger()->writeln("This might take a while...");
$posts = DB::table('posts')->get(['post_id']); $posts = DB::table('posts')->get(['post_id']);

View file

@ -19,7 +19,7 @@ class ServeCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Sets up a local development server.'; return 'Sets up a local development server.';
} }
@ -27,7 +27,7 @@ class ServeCommand extends Command
/** /**
* Sends the php serve command via the exec command. * Sends the php serve command via the exec command.
*/ */
public function execute() public function execute(): void
{ {
$document_root = addslashes(path('public')); $document_root = addslashes(path('public'));
$router_proxy = addslashes(path('server.php')); $router_proxy = addslashes(path('server.php'));

View file

@ -20,7 +20,7 @@ class SessionPurgeCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Purge expired sessions.'; return 'Purge expired sessions.';
} }
@ -28,7 +28,7 @@ class SessionPurgeCommand extends Command
/** /**
* Purges sessions. * Purges sessions.
*/ */
public function execute() public function execute(): void
{ {
DB::table('sessions') DB::table('sessions')
->where('session_expire', '<', time()) ->where('session_expire', '<', time())

View file

@ -22,7 +22,7 @@ class SetupCommand extends Command
* A quick description of this command. * A quick description of this command.
* @return string. * @return string.
*/ */
public function brief() public function brief(): string
{ {
return 'Adds the required data to the tables, only needed once after the initial migration.'; return 'Adds the required data to the tables, only needed once after the initial migration.';
} }
@ -30,7 +30,7 @@ class SetupCommand extends Command
/** /**
* Adds data to the database required to get everything running. * Adds data to the database required to get everything running.
*/ */
public function execute() public function execute(): void
{ {
// Check if the users table has user with id 1 // Check if the users table has user with id 1
$userCheck = DB::table('users')->where('user_id', 1)->count(); $userCheck = DB::table('users')->where('user_id', 1)->count();

View file

@ -22,10 +22,10 @@ class AuthController extends Controller
{ {
/** /**
* Touch the login rate limit. * Touch the login rate limit.
* @param $user int The ID of the user that attempted to log in. * @param int $user The ID of the user that attempted to log in.
* @param $sucess bool Whether the login attempt was successful. * @param bool $success Whether the login attempt was successful.
*/ */
protected function touchRateLimit($user, $success = false) protected function touchRateLimit(int $user, bool $success = false): void
{ {
DB::table('login_attempts') DB::table('login_attempts')
->insert([ ->insert([
@ -40,7 +40,7 @@ class AuthController extends Controller
* End the current session. * End the current session.
* @return string * @return string
*/ */
public function logout() public function logout(): string
{ {
if (!session_check()) { if (!session_check()) {
return view('auth/logout'); return view('auth/logout');
@ -50,14 +50,14 @@ class AuthController extends Controller
CurrentSession::stop(); CurrentSession::stop();
// Return true indicating a successful logout // Return true indicating a successful logout
redirect(route('auth.login')); return redirect(route('auth.login'));
} }
/** /**
* Login page. * Login page.
* @return string * @return string
*/ */
public function login() public function login(): string
{ {
if (!session_check()) { if (!session_check()) {
return view('auth/login'); return view('auth/login');
@ -151,7 +151,7 @@ class AuthController extends Controller
* Do a registration attempt. * Do a registration attempt.
* @return string * @return string
*/ */
public function register() public function register(): string
{ {
// Preliminarily set registration to failed // Preliminarily set registration to failed
$redirect = route('auth.register'); $redirect = route('auth.register');
@ -264,7 +264,7 @@ class AuthController extends Controller
* Do a activation attempt. * Do a activation attempt.
* @return string * @return string
*/ */
public function activate() public function activate(): string
{ {
// Preliminarily set activation to failed // Preliminarily set activation to failed
$redirect = route('main.index'); $redirect = route('main.index');
@ -314,7 +314,7 @@ class AuthController extends Controller
* Do a reactivation preparation attempt. * Do a reactivation preparation attempt.
* @return string * @return string
*/ */
public function reactivate() public function reactivate(): string
{ {
// Validate session // Validate session
if (!session_check()) { if (!session_check()) {
@ -361,7 +361,7 @@ class AuthController extends Controller
* Do a password reset attempt. * Do a password reset attempt.
* @return string * @return string
*/ */
public function resetPassword() public function resetPassword(): string
{ {
// Validate session // Validate session
if (!session_check()) { if (!session_check()) {
@ -427,7 +427,7 @@ class AuthController extends Controller
* Send the activation e-mail * Send the activation e-mail
* @param User $user * @param User $user
*/ */
private function sendActivationMail($user) private function sendActivationMail(User $user): void
{ {
// Generate activation key // Generate activation key
$activate = ActionCode::generate('ACTIVATE', $user->id); $activate = ActionCode::generate('ACTIVATE', $user->id);
@ -461,7 +461,7 @@ class AuthController extends Controller
* Send the activation e-mail * Send the activation e-mail
* @param User $user * @param User $user
*/ */
private function sendPasswordMail($user) private function sendPasswordMail(User $user): void
{ {
// Generate the verification key // Generate the verification key
$verk = ActionCode::generate('LOST_PASS', $user->id); $verk = ActionCode::generate('LOST_PASS', $user->id);

View file

@ -31,16 +31,16 @@ class ChatController extends Controller
/** /**
* Redirects the user to the chat client. * Redirects the user to the chat client.
*/ */
public function redirect() public function redirect(): string
{ {
redirect(config('chat.webclient')); return redirect(config('chat.webclient'));
} }
/** /**
* Serves the settings for a Sakurako chat. * Serves the settings for a Sakurako chat.
* @return string * @return string
*/ */
public function settings() public function settings(): string
{ {
$settings = new Settings; $settings = new Settings;
$settings->loadStandard(); $settings->loadStandard();
@ -59,7 +59,7 @@ class ChatController extends Controller
* Resolves urls. * Resolves urls.
* @return string * @return string
*/ */
public function resolve() public function resolve(): string
{ {
$data = json_decode(file_get_contents('php://input')); $data = json_decode(file_get_contents('php://input'));
$info = new LinkInfo; $info = new LinkInfo;
@ -84,25 +84,25 @@ class ChatController extends Controller
* Handles the authentication for a chat server. * Handles the authentication for a chat server.
* @return string * @return string
*/ */
public function auth() public function auth(): ?string
{ {
return; return null;
} }
/** /**
* IRC page. * IRC page.
* @return string * @return string
*/ */
public function irc() public function irc(): ?string
{ {
return; return null;
} }
/** /**
* Legacy auth, for SockLegacy. Remove when the old chat server finally dies. * Legacy auth, for SockLegacy. Remove when the old chat server finally dies.
* @return string * @return string
*/ */
public function authLegacy() public function authLegacy(): string
{ {
$user = User::construct($_GET['arg1'] ?? null); $user = User::construct($_GET['arg1'] ?? null);
$session = new Session($_GET['arg2'] ?? null); $session = new Session($_GET['arg2'] ?? null);

View file

@ -23,7 +23,7 @@ class CommentsController extends Controller
* @param int $reply * @param int $reply
* @return string * @return string
*/ */
public function post($category = '', $reply = 0) public function post(string $category = '', int $reply = 0): string
{ {
// Check if the user can comment // Check if the user can comment
if (session_check()) { if (session_check()) {
@ -70,7 +70,7 @@ class CommentsController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function delete($id = 0) public function delete(int $id = 0): string
{ {
// Check if the user can delete comments // Check if the user can delete comments
if (!CurrentSession::$user->perms->commentsDelete) { if (!CurrentSession::$user->perms->commentsDelete) {
@ -102,7 +102,7 @@ class CommentsController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function vote($id = 0) public function vote(int $id = 0): string
{ {
$vote = $_REQUEST['vote'] ?? 0; $vote = $_REQUEST['vote'] ?? 0;
$vote = $vote != 0; $vote = $vote != 0;

View file

@ -47,7 +47,7 @@ class Controller
* @param int $operators * @param int $operators
* @return string * @return string
*/ */
public function json($object, $operators = null) public function json($object, int $operators = null): string
{ {
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
return json_encode($object, $operators); return json_encode($object, $operators);

View file

@ -26,7 +26,7 @@ class FileController extends Controller
/** /**
* Possible modes. * Possible modes.
*/ */
const MODES = [ private const MODES = [
'avatar', 'avatar',
'background', 'background',
'header', 'header',
@ -39,7 +39,7 @@ class FileController extends Controller
* @param string $name * @param string $name
* @return string * @return string
*/ */
private function serve($data, $mime, $name) private function serve(string $data, string $mime, string $name): string
{ {
header("Content-Disposition: inline; filename={$name}"); header("Content-Disposition: inline; filename={$name}");
header("Content-Type: {$mime}"); header("Content-Type: {$mime}");
@ -50,9 +50,10 @@ class FileController extends Controller
* Handles file uploads. * Handles file uploads.
* @param string $mode * @param string $mode
* @param array $file * @param array $file
* @return array * @param User $user
* @throws FileException
*/ */
private function upload($mode, $file, $user) private function upload(string $mode, array $file, User $user): void
{ {
// Handle errors // Handle errors
switch ($file['error']) { switch ($file['error']) {
@ -135,8 +136,9 @@ class FileController extends Controller
/** /**
* Deletes a file. * Deletes a file.
* @param string $mode * @param string $mode
* @param User $user
*/ */
public function delete($mode, $user) public function delete(string $mode, User $user): void
{ {
$fileId = $user->{$mode}; $fileId = $user->{$mode};
@ -151,7 +153,7 @@ class FileController extends Controller
* @param array $params * @param array $params
* @return string * @return string
*/ */
public function __call($method, $params) public function __call(string $method, array $params): ?string
{ {
if (!in_array($method, self::MODES)) { if (!in_array($method, self::MODES)) {
throw new HttpRouteNotFoundException; throw new HttpRouteNotFoundException;
@ -183,7 +185,7 @@ class FileController extends Controller
return $this->json(compact('error')); return $this->json(compact('error'));
} elseif ($_SERVER['REQUEST_METHOD'] === 'DELETE') { } elseif ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
$this->delete($method, $user); $this->delete($method, $user);
return; return null;
} }
} }

View file

@ -27,7 +27,7 @@ class ForumController extends Controller
* Renders the forum index * Renders the forum index
* @return string * @return string
*/ */
public function index() public function index(): string
{ {
// Get the most active topics // Get the most active topics
$activeTopicsIds = DB::table('posts') $activeTopicsIds = DB::table('posts')
@ -109,28 +109,28 @@ class ForumController extends Controller
/** /**
* Renders a forum. * Renders a forum.
* @param int $id
* @throws HttpRouteNotFoundException
* @return string * @return string
*/ */
public function forum($id = 0) public function forum(int $id = 0): string
{ {
$forum = new Forum($id); $forum = new Forum($id);
// Redirect forum id 0 to the main page // Redirect forum id 0 to the main page
if ($forum->id === 0) { if ($forum->id === 0) {
redirect(route('forums.index')); return redirect(route('forums.index'));
return;
} }
// Check if the forum exists // Check if the forum exists
if ($forum->id < 0 if ($forum->id < 0
|| !$forum->perms->view) { || !$forum->perms->view) {
throw new HttpRouteNotFoundException(); throw new HttpRouteNotFoundException;
} }
// Check if the forum isn't a link // Check if the forum isn't a link
if ($forum->type === 2) { if ($forum->type === 2) {
redirect($forum->link); return redirect($forum->link);
return;
} }
return view('forum/forum', compact('forum')); return view('forum/forum', compact('forum'));
@ -139,12 +139,14 @@ class ForumController extends Controller
/** /**
* Marks an entire forum as read. * Marks an entire forum as read.
* @param int $id * @param int $id
* @throws HttpRouteNotFoundException
* @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function markRead($id = 0) public function markRead(int $id = 0): string
{ {
if (!session_check('s')) { if (!session_check('s')) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
$forum = new Forum($id); $forum = new Forum($id);
@ -152,11 +154,11 @@ class ForumController extends Controller
// Check if the forum exists // Check if the forum exists
if ($forum->id < 1 if ($forum->id < 1
|| !$forum->perms->view) { || !$forum->perms->view) {
throw new HttpRouteNotFoundException(); throw new HttpRouteNotFoundException;
} }
$forum->trackUpdateAll(CurrentSession::$user->id); $forum->trackUpdateAll(CurrentSession::$user->id);
redirect(route('forums.forum', $forum->id)); return redirect(route('forums.forum', $forum->id));
} }
} }

View file

@ -26,7 +26,7 @@ class PostController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function find($id = 0) public function find(int $id = 0): string
{ {
$post = new Post($id); $post = new Post($id);
$topic = new Topic($post->topic); $topic = new Topic($post->topic);
@ -55,7 +55,7 @@ class PostController extends Controller
$topicLink .= "?page={$postAt}"; $topicLink .= "?page={$postAt}";
} }
redirect("{$topicLink}#p{$post->id}"); return redirect("{$topicLink}#p{$post->id}");
} }
/** /**
@ -63,7 +63,7 @@ class PostController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function raw($id = 0) public function raw(int $id = 0): string
{ {
$post = new Post($id); $post = new Post($id);
$topic = new Topic($post->topic); $topic = new Topic($post->topic);
@ -84,7 +84,7 @@ class PostController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function edit($id = 0) public function edit(int $id = 0): string
{ {
$title = $_POST['title'] ?? null; $title = $_POST['title'] ?? null;
$text = $_POST['text'] ?? null; $text = $_POST['text'] ?? null;
@ -176,15 +176,15 @@ class PostController extends Controller
$postLink = route('forums.post', $post->id); $postLink = route('forums.post', $post->id);
redirect($postLink); return redirect($postLink);
} }
/** /**
* Deletes a post. * Deletes a post.
* @param int $id * @param int $id
* @return string * @throws HttpMethodNotAllowedException
*/ */
public function delete($id = 0) public function delete(int $id = 0): void
{ {
$post = new Post($id); $post = new Post($id);
$topic = new Topic($post->topic); $topic = new Topic($post->topic);
@ -211,7 +211,7 @@ class PostController extends Controller
// Check if the forum exists // Check if the forum exists
if ($noAccess || $noDelete) { if ($noAccess || $noDelete) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
// Check if the topic only has 1 post // Check if the topic only has 1 post

View file

@ -26,7 +26,7 @@ class TopicController extends Controller
* @throws HttpRouteNotFoundException * @throws HttpRouteNotFoundException
* @return string * @return string
*/ */
public function view($id = 0) public function view(int $id = 0): string
{ {
$topic = new Topic($id); $topic = new Topic($id);
$forum = new Forum($topic->forum); $forum = new Forum($topic->forum);
@ -49,7 +49,7 @@ class TopicController extends Controller
* @throws HttpRouteNotFoundException * @throws HttpRouteNotFoundException
* @return array * @return array
*/ */
private function modBase($id) private function modBase(int $id): array
{ {
$topic = new Topic($id); $topic = new Topic($id);
$forum = new Forum($topic->forum); $forum = new Forum($topic->forum);
@ -69,7 +69,7 @@ class TopicController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function sticky($id) public function sticky(int $id): string
{ {
extract($this->modBase($id)); extract($this->modBase($id));
@ -80,7 +80,7 @@ class TopicController extends Controller
$topic->type = $topic->type !== 1 ? 1 : 0; $topic->type = $topic->type !== 1 ? 1 : 0;
$topic->update(); $topic->update();
redirect(route('forums.topic', $topic->id)); return redirect(route('forums.topic', $topic->id));
} }
/** /**
@ -89,7 +89,7 @@ class TopicController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function announce($id) public function announce(int $id): string
{ {
extract($this->modBase($id)); extract($this->modBase($id));
@ -100,7 +100,7 @@ class TopicController extends Controller
$topic->type = $topic->type !== 2 ? 2 : 0; $topic->type = $topic->type !== 2 ? 2 : 0;
$topic->update(); $topic->update();
redirect(route('forums.topic', $topic->id)); return redirect(route('forums.topic', $topic->id));
} }
/** /**
@ -109,7 +109,7 @@ class TopicController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function lock($id) public function lock(int $id): string
{ {
extract($this->modBase($id)); extract($this->modBase($id));
@ -120,7 +120,7 @@ class TopicController extends Controller
$topic->status = $topic->status !== 1 ? 1 : 0; $topic->status = $topic->status !== 1 ? 1 : 0;
$topic->update(); $topic->update();
redirect(route('forums.topic', $topic->id)); return redirect(route('forums.topic', $topic->id));
} }
/** /**
@ -129,7 +129,7 @@ class TopicController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function delete($id) public function delete(int $id): string
{ {
extract($this->modBase($id)); extract($this->modBase($id));
@ -146,7 +146,7 @@ class TopicController extends Controller
throw new HttpMethodNotAllowedException; throw new HttpMethodNotAllowedException;
} }
redirect($redirect); return redirect($redirect);
} }
/** /**
@ -155,7 +155,7 @@ class TopicController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function restore($id) public function restore(int $id): string
{ {
extract($this->modBase($id)); extract($this->modBase($id));
@ -167,7 +167,7 @@ class TopicController extends Controller
$topic->move($topic->oldForum, false); $topic->move($topic->oldForum, false);
} }
redirect(route('forums.topic', $topic->id)); return redirect(route('forums.topic', $topic->id));
} }
/** /**
@ -176,7 +176,7 @@ class TopicController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function move($id) public function move(int $id): string
{ {
extract($this->modBase($id)); extract($this->modBase($id));
$dest_forum = new Forum($_REQUEST['forum_id'] ?? 0); $dest_forum = new Forum($_REQUEST['forum_id'] ?? 0);
@ -189,7 +189,7 @@ class TopicController extends Controller
$topic->move($dest_forum->id); $topic->move($dest_forum->id);
redirect(route('forums.topic', $topic->id)); return redirect(route('forums.topic', $topic->id));
} }
/** /**
@ -197,7 +197,7 @@ class TopicController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function reply($id = 0) public function reply(int $id = 0): string
{ {
$text = $_POST['text'] ?? null; $text = $_POST['text'] ?? null;
@ -272,7 +272,7 @@ class TopicController extends Controller
$postLink = route('forums.post', $post->id); $postLink = route('forums.post', $post->id);
// Head to the post // Head to the post
redirect($postLink); return redirect($postLink);
} }
/** /**
@ -280,7 +280,7 @@ class TopicController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function create($id = 0) public function create(int $id = 0): string
{ {
$title = $_POST['title'] ?? null; $title = $_POST['title'] ?? null;
$text = $_POST['text'] ?? null; $text = $_POST['text'] ?? null;
@ -360,8 +360,7 @@ class TopicController extends Controller
$postLink = route('forums.post', $post->id); $postLink = route('forums.post', $post->id);
// Head to the post // Head to the post
redirect($postLink); return redirect($postLink);
return;
} }
return view('forum/topic', compact('forum')); return view('forum/topic', compact('forum'));

View file

@ -24,7 +24,7 @@ class FriendsController extends Controller
* @param string $title * @param string $title
* @param string $text * @param string $text
*/ */
private function addNotification($friend, $user, $title, $text = "") private function addNotification(User $friend, User $user, string $title, string $text = ""): void
{ {
$alert = new Notification; $alert = new Notification;
@ -44,7 +44,7 @@ class FriendsController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function add($id = 0) public function add(int $id = 0): string
{ {
$user = CurrentSession::$user; $user = CurrentSession::$user;
@ -105,7 +105,7 @@ class FriendsController extends Controller
* @param int $id * @param int $id
* @return string * @return string
*/ */
public function remove($id = 0) public function remove(int $id = 0): string
{ {
$user = CurrentSession::$user; $user = CurrentSession::$user;

View file

@ -20,7 +20,7 @@ class HelperController extends Controller
* Parsed BBcode from a post request. * Parsed BBcode from a post request.
* @return string * @return string
*/ */
public function bbcodeParse() public function bbcodeParse(): string
{ {
return BBParser::toHTML(htmlentities($_POST['text'] ?? ''), CurrentSession::$user); return BBParser::toHTML(htmlentities($_POST['text'] ?? ''), CurrentSession::$user);
} }

View file

@ -17,7 +17,7 @@ class InfoController extends Controller
* Renders the terms of service. * Renders the terms of service.
* @return string * @return string
*/ */
public function terms() public function terms(): string
{ {
return view('info/terms'); return view('info/terms');
} }
@ -26,7 +26,7 @@ class InfoController extends Controller
* Renders the privacy policy. * Renders the privacy policy.
* @return string * @return string
*/ */
public function privacy() public function privacy(): string
{ {
return view('info/privacy'); return view('info/privacy');
} }
@ -35,7 +35,7 @@ class InfoController extends Controller
* Renders the contact page. * Renders the contact page.
* @return string * @return string
*/ */
public function contact() public function contact(): string
{ {
$contact = config('contact'); $contact = config('contact');
@ -46,7 +46,7 @@ class InfoController extends Controller
* Renders the rules page. * Renders the rules page.
* @return string * @return string
*/ */
public function rules() public function rules(): string
{ {
return view('info/rules'); return view('info/rules');
} }
@ -55,7 +55,7 @@ class InfoController extends Controller
* Renders the welcome page. * Renders the welcome page.
* @return string * @return string
*/ */
public function welcome() public function welcome(): string
{ {
return view('info/welcome'); return view('info/welcome');
} }

View file

@ -29,7 +29,7 @@ class Controller extends BaseController
* Generates the navigation. * Generates the navigation.
* @return array * @return array
*/ */
public function navigation() public function navigation(): array
{ {
$nav = []; $nav = [];

View file

@ -19,7 +19,7 @@ class OverviewController extends Controller
* Renders the base overview page. * Renders the base overview page.
* @return string * @return string
*/ */
public function index() public function index(): string
{ {
return view('manage/overview/index'); return view('manage/overview/index');
} }
@ -28,7 +28,7 @@ class OverviewController extends Controller
* Gets the data for the overview page. * Gets the data for the overview page.
* @return string * @return string
*/ */
public function data() public function data(): string
{ {
$data = new \stdClass; $data = new \stdClass;

View file

@ -23,7 +23,7 @@ class MetaController extends Controller
* Serves the site index. * Serves the site index.
* @return string * @return string
*/ */
public function index() public function index(): string
{ {
// Get the newest user // Get the newest user
$newestUserId = DB::table('users') $newestUserId = DB::table('users')
@ -85,31 +85,22 @@ class MetaController extends Controller
* Displays the FAQ. * Displays the FAQ.
* @return string * @return string
*/ */
public function faq() public function faq(): string
{ {
// Get faq entries // Get faq entries
$faq = DB::table('faq') $questions = DB::table('faq')
->orderBy('faq_id') ->orderBy('faq_id')
->get(); ->get();
// Set parse variables return view('meta/faq', compact('questions'));
Template::vars([
'page' => [
'title' => 'Frequently Asked Questions',
'questions' => $faq,
],
]);
// Print page contents
return Template::render('meta/faq');
} }
/** /**
* Search page. * Search page.
* @return string * @return string
*/ */
public function search() public function search(): string
{ {
return Template::render('meta/search'); return view('meta/search');
} }
} }

View file

@ -21,9 +21,10 @@ class NewsController extends Controller
/** /**
* Shows all posts in a specific category. * Shows all posts in a specific category.
* @param string $category * @param string $category
* @throws HttpRouteNotFoundException
* @return string * @return string
*/ */
public function category($category = '') public function category(string $category = ''): string
{ {
// Check if the category is set // Check if the category is set
if ($category === '') { if ($category === '') {
@ -35,7 +36,7 @@ class NewsController extends Controller
$category = new Category($category); $category = new Category($category);
if (!$category->posts()) { if (!$category->posts()) {
throw new HttpRouteNotFoundException(); throw new HttpRouteNotFoundException;
} }
return view('news/category', compact('category')); return view('news/category', compact('category'));
@ -44,15 +45,16 @@ class NewsController extends Controller
/** /**
* Returns a news post. * Returns a news post.
* @param int $id * @param int $id
* @throws HttpRouteNotFoundException
* @return string * @return string
*/ */
public function post($id = 0) public function post(int $id = 0): string
{ {
// Create the post object // Create the post object
$post = new Post($id); $post = new Post($id);
if (!$post->id) { if (!$post->id) {
throw new HttpRouteNotFoundException(); throw new HttpRouteNotFoundException;
} }
return view('news/post', compact('post')); return view('news/post', compact('post'));

View file

@ -20,7 +20,7 @@ class NotificationsController extends Controller
* Get the notification JSON object for the currently authenticated user. * Get the notification JSON object for the currently authenticated user.
* @return string * @return string
*/ */
public function notifications() public function notifications(): string
{ {
return $this->json(CurrentSession::$user->notifications()); return $this->json(CurrentSession::$user->notifications());
} }
@ -31,7 +31,7 @@ class NotificationsController extends Controller
* @param int * @param int
* @return string * @return string
*/ */
public function mark($id = 0) public function mark(int $id = 0): string
{ {
if (!CurrentSession::$user->activated) { if (!CurrentSession::$user->activated) {
return '0'; return '0';

View file

@ -22,7 +22,7 @@ class PremiumController extends Controller
/** /**
* The amount of premium a user received per period. * The amount of premium a user received per period.
*/ */
const PERIOD_PER_PAYMENT = 2628000; private const PERIOD_PER_PAYMENT = 2628000;
/** /**
* Constructor. * Constructor.
@ -37,7 +37,7 @@ class PremiumController extends Controller
* Returns the premium purchase index. * Returns the premium purchase index.
* @return string * @return string
*/ */
public function index() public function index(): string
{ {
$price = config('premium.price_per_month'); $price = config('premium.price_per_month');
$amountLimit = config('premium.max_months_at_once'); $amountLimit = config('premium.max_months_at_once');
@ -48,10 +48,10 @@ class PremiumController extends Controller
* Handles a purchase request. * Handles a purchase request.
* @return string * @return string
*/ */
public function purchase() public function purchase(): string
{ {
// Get values from post // Get values from post
$months = isset($_POST['months']) ? $_POST['months'] : 0; $months = $_POST['months'] ?? 0;
// Check if the session is valid // Check if the session is valid
if (!session_check() if (!session_check()
@ -67,8 +67,7 @@ class PremiumController extends Controller
// Check months // Check months
if ($months < 1 if ($months < 1
|| $months > $amountLimit) { || $months > $amountLimit) {
redirect(route('premium.error')); return redirect(route('premium.error'));
return;
} }
$pricePerMonth = config('premium.price_per_month'); $pricePerMonth = config('premium.price_per_month');
@ -97,26 +96,25 @@ class PremiumController extends Controller
// Attempt to create a transaction // Attempt to create a transaction
if (!$transaction) { if (!$transaction) {
redirect(route('premium.error')); return redirect(route('premium.error'));
return;
} }
// Store the amount of months in the global session array // Store the amount of months in the global session array
$_SESSION['premiumMonths'] = (int) $months; $_SESSION['premiumMonths'] = (int) $months;
redirect($transaction); return redirect($transaction);
} }
/** /**
* Handles the data returned by PayPal. * Handles the data returned by PayPal.
* @return string * @return string
*/ */
public function handle() public function handle(): string
{ {
$success = isset($_GET['success']); $success = isset($_GET['success']);
$payment = isset($_GET['paymentId']) ? $_GET['paymentId'] : null; $payment = $_GET['paymentId'] ?? null;
$payer = isset($_GET['PayerID']) ? $_GET['PayerID'] : null; $payer = $_GET['PayerID'] ?? null;
$months = isset($_SESSION['premiumMonths']) ? $_SESSION['premiumMonths'] : null; $months = $_SESSION['premiumMonths'] ?? null;
$successRoute = route('premium.complete'); $successRoute = route('premium.complete');
$failRoute = route('premium.error'); $failRoute = route('premium.error');
@ -125,8 +123,7 @@ class PremiumController extends Controller
|| !$payment || !$payment
|| !$payer || !$payer
|| !$months) { || !$months) {
redirect($failRoute); return redirect($failRoute);
return;
} }
// Attempt to complete the transaction // Attempt to complete the transaction
@ -137,20 +134,19 @@ class PremiumController extends Controller
} }
if (!$finalise) { if (!$finalise) {
redirect($failRoute); return redirect($failRoute);
return;
} }
CurrentSession::$user->addPremium(self::PERIOD_PER_PAYMENT * $months); CurrentSession::$user->addPremium(self::PERIOD_PER_PAYMENT * $months);
redirect($successRoute); return redirect($successRoute);
} }
/** /**
* Presents the user with a thank you <3. * Presents the user with a thank you <3.
* @return string * @return string
*/ */
public function complete() public function complete(): string
{ {
return view('premium/complete'); return view('premium/complete');
} }
@ -159,7 +155,7 @@ class PremiumController extends Controller
* Errors. * Errors.
* @return string * @return string
*/ */
public function error() public function error(): string
{ {
return view('premium/error'); return view('premium/error');
} }

View file

@ -19,12 +19,13 @@ class AccountController extends Controller
{ {
/** /**
* Renders the profile changing page. * Renders the profile changing page.
* @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function profile() public function profile(): string
{ {
if (!CurrentSession::$user->perms->changeProfile) { if (!CurrentSession::$user->perms->changeProfile) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
if (session_check()) { if (session_check()) {
@ -87,7 +88,7 @@ class AccountController extends Controller
* Details such as email, username and password. * Details such as email, username and password.
* @return string * @return string
*/ */
public function details() public function details(): string
{ {
$user = CurrentSession::$user; $user = CurrentSession::$user;
$edit_usern = $user->perms->changeUsername; $edit_usern = $user->perms->changeUsername;
@ -225,12 +226,13 @@ class AccountController extends Controller
/** /**
* Renders the rank management page. * Renders the rank management page.
* @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function ranks() public function ranks(): string
{ {
if (!CurrentSession::$user->perms->manageRanks) { if (!CurrentSession::$user->perms->manageRanks) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
$rank = $_POST['rank'] ?? null; $rank = $_POST['rank'] ?? null;
@ -267,19 +269,20 @@ class AccountController extends Controller
CurrentSession::$user->setMainRank($rank); CurrentSession::$user->setMainRank($rank);
redirect($redirect); return redirect($redirect);
return;
} }
return view('settings/account/ranks', compact('locked')); return view('settings/account/ranks', compact('locked'));
} }
/** /**
* Renders the userpage editing page. * Renders the userpage editing page.
* @throws HttpMethodNotAllowedException
* @return string
*/ */
public function userpage() public function userpage(): string
{ {
if (!CurrentSession::$user->perms->changeUserpage) { if (!CurrentSession::$user->perms->changeUserpage) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
$userpage = $_POST['userpage'] ?? null; $userpage = $_POST['userpage'] ?? null;
@ -308,12 +311,13 @@ class AccountController extends Controller
/** /**
* Renders the signature changing page. * Renders the signature changing page.
* @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function signature() public function signature(): string
{ {
if (!CurrentSession::$user->perms->changeSignature) { if (!CurrentSession::$user->perms->changeSignature) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
$signature = $_POST['signature'] ?? null; $signature = $_POST['signature'] ?? null;

View file

@ -21,7 +21,7 @@ class AdvancedController extends Controller
* Renders the session management page. * Renders the session management page.
* @return string * @return string
*/ */
public function sessions() public function sessions(): string
{ {
$id = $_POST['id'] ?? null; $id = $_POST['id'] ?? null;
$all = isset($_POST['all']); $all = isset($_POST['all']);
@ -45,11 +45,9 @@ class AdvancedController extends Controller
return view('global/information', compact('message', 'redirect')); return view('global/information', compact('message', 'redirect'));
} }
// Delete it
$session->delete(); $session->delete();
redirect($redirect); return redirect($redirect);
return;
} }
$sessions = CurrentSession::$user->sessions(); $sessions = CurrentSession::$user->sessions();
@ -62,7 +60,7 @@ class AdvancedController extends Controller
* Renders the deactivation page. * Renders the deactivation page.
* @return string * @return string
*/ */
public function deactivate() public function deactivate(): string
{ {
if (!CurrentSession::$user->perms->deactivateAccount) { if (!CurrentSession::$user->perms->deactivateAccount) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException();

View file

@ -29,7 +29,7 @@ class Controller extends BaseController
* Generates the navigation. * Generates the navigation.
* @return array * @return array
*/ */
public function navigation() public function navigation(): array
{ {
$nav = []; $nav = [];

View file

@ -18,12 +18,13 @@ class FriendsController extends Controller
{ {
/** /**
* Gets friends listing * Gets friends listing
* @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function listing() public function listing(): string
{ {
if (!CurrentSession::$user->perms->manageFriends) { if (!CurrentSession::$user->perms->manageFriends) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
return view('settings/friends/listing'); return view('settings/friends/listing');
@ -31,12 +32,13 @@ class FriendsController extends Controller
/** /**
* Gets friend requests listing * Gets friend requests listing
* @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function requests() public function requests(): string
{ {
if (!CurrentSession::$user->perms->manageFriends) { if (!CurrentSession::$user->perms->manageFriends) {
throw new HttpMethodNotAllowedException(); throw new HttpMethodNotAllowedException;
} }
return view('settings/friends/requests'); return view('settings/friends/requests');

View file

@ -17,7 +17,7 @@ class StatusController extends Controller
* Renders the base status page. * Renders the base status page.
* @return string * @return string
*/ */
public function index() public function index(): string
{ {
return view('status/index'); return view('status/index');
} }

View file

@ -23,10 +23,10 @@ class UserController extends Controller
{ {
/** /**
* Display the profile of a user. * Display the profile of a user.
* @param int $id * @param int|string $id
* @return string * @return string
*/ */
public function profile($id = 0) public function profile($id = 0): string
{ {
// Get the user's context // Get the user's context
$profile = User::construct($id); $profile = User::construct($id);
@ -41,8 +41,7 @@ class UserController extends Controller
// Redirect if so // Redirect if so
if ($check) { if ($check) {
redirect(route('user.profile', $check->user_id)); return redirect(route('user.profile', $check->user_id));
return;
} }
} }
@ -55,7 +54,7 @@ class UserController extends Controller
* @throws HttpRouteNotFoundException * @throws HttpRouteNotFoundException
* @return string * @return string
*/ */
public function nowPlaying($id) public function nowPlaying(int $id): string
{ {
$user = User::construct($id); $user = User::construct($id);
@ -83,7 +82,7 @@ class UserController extends Controller
* @throws HttpMethodNotAllowedException * @throws HttpMethodNotAllowedException
* @return string * @return string
*/ */
public function members($rank = null) public function members(int $rank = null): string
{ {
if (!CurrentSession::$user->activated) { if (!CurrentSession::$user->activated) {
throw new HttpMethodNotAllowedException; throw new HttpMethodNotAllowedException;
@ -114,7 +113,7 @@ class UserController extends Controller
* Report a user. * Report a user.
* @param int $id * @param int $id
*/ */
public function report($id = 0) public function report(int $id = 0): string
{ {
return view('user/report'); return view('user/report');
} }

View file

@ -31,7 +31,7 @@ class CurrentSession
* @param string $session * @param string $session
* @param string $ip * @param string $ip
*/ */
public static function start($user, $session, $ip) public static function start(int $user, string $session, string $ip): void
{ {
// Check if a PHP session was already started and if not start one // Check if a PHP session was already started and if not start one
if (session_status() !== PHP_SESSION_ACTIVE) { if (session_status() !== PHP_SESSION_ACTIVE) {
@ -57,7 +57,7 @@ class CurrentSession
/** /**
* Stop the current session * Stop the current session
*/ */
public static function stop() public static function stop(): void
{ {
self::$session->delete(); self::$session->delete();
session_regenerate_id(true); session_regenerate_id(true);
@ -74,7 +74,7 @@ class CurrentSession
* @param int $length * @param int $length
* @return Session * @return Session
*/ */
public static function create($user, $ip, $country, $agent = null, $remember = false, $length = 604800) public static function create(int $user, string $ip, string $country, string $agent = null, bool $remember = false, int $length = 604800)
{ {
return Session::create($user, $ip, $country, $agent, $remember, $length); return Session::create($user, $ip, $country, $agent, $remember, $length);
} }

View file

@ -9,6 +9,7 @@ namespace Sakura;
use Illuminate\Database\Capsule\Manager; use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\ConnectionResolver; use Illuminate\Database\ConnectionResolver;
use Illuminate\Database\Migrations\DatabaseMigrationRepository; use Illuminate\Database\Migrations\DatabaseMigrationRepository;
use Illuminate\Database\Schema\Builder;
/** /**
* The Illuminate (Laravel) database wrapper. * The Illuminate (Laravel) database wrapper.
@ -21,7 +22,7 @@ class DB extends Manager
* Start the database module. * Start the database module.
* @param array $details * @param array $details
*/ */
public static function connect($details) public static function connect(array $details): void
{ {
$capsule = new static; $capsule = new static;
$capsule->addConnection($details); $capsule->addConnection($details);
@ -32,7 +33,7 @@ class DB extends Manager
* Gets the migration repository (surprise surprise). * Gets the migration repository (surprise surprise).
* @return DatabaseMigrationRepository * @return DatabaseMigrationRepository
*/ */
public static function getMigrationRepository() public static function getMigrationRepository(): DatabaseMigrationRepository
{ {
$resolver = new ConnectionResolver(['database' => self::connection()]); $resolver = new ConnectionResolver(['database' => self::connection()]);
$repository = new DatabaseMigrationRepository($resolver, 'migrations'); $repository = new DatabaseMigrationRepository($resolver, 'migrations');
@ -42,9 +43,9 @@ class DB extends Manager
/** /**
* Get the migration schema builder. * Get the migration schema builder.
* @return \Illuminate\Database\Schema\Builder * @return Builder
*/ */
public static function getSchemaBuilder() public static function getSchemaBuilder(): Builder
{ {
return self::connection()->getSchemaBuilder(); return self::connection()->getSchemaBuilder();
} }

View file

@ -26,7 +26,7 @@ class ExceptionHandler
/** /**
* Register as the error and exception handler. * Register as the error and exception handler.
*/ */
public static function register() public static function register(): void
{ {
set_exception_handler([static::class, 'exception']); set_exception_handler([static::class, 'exception']);
set_error_handler([static::class, 'error']); set_error_handler([static::class, 'error']);
@ -36,7 +36,7 @@ class ExceptionHandler
* The entry point for set_exception_handler. * The entry point for set_exception_handler.
* @param Throwable $ex * @param Throwable $ex
*/ */
public static function exception(Throwable $ex) public static function exception(Throwable $ex): void
{ {
$report = strlen(config('dev.report_host')) > 0; $report = strlen(config('dev.report_host')) > 0;
@ -53,8 +53,9 @@ class ExceptionHandler
* @param string $message * @param string $message
* @param string $file * @param string $file
* @param int $line * @param int $line
* @throws ErrorException
*/ */
public static function error($severity, $message, $file, $line) public static function error(int $severity, string $message, string $file, int $line): void
{ {
throw new ErrorException($message, 0, $severity, $file, $line); throw new ErrorException($message, 0, $severity, $file, $line);
} }
@ -64,7 +65,7 @@ class ExceptionHandler
* @param Throwable $ex * @param Throwable $ex
* @param bool $reported * @param bool $reported
*/ */
private static function view(Throwable $ex, $reported = false) private static function view(Throwable $ex, bool $reported = false): void
{ {
http_response_code(500); http_response_code(500);
@ -98,7 +99,7 @@ class ExceptionHandler
* @param Throwable $ex * @param Throwable $ex
* @param string $destination * @param string $destination
*/ */
private static function report(Throwable $ex, $destination) private static function report(Throwable $ex, string $destination): void
{ {
$send = new stdClass; $send = new stdClass;
$send->Date = date('c'); $send->Date = date('c');

View file

@ -65,7 +65,7 @@ class File
* @param int $expire * @param int $expire
* @return File * @return File
*/ */
public static function create($data, $name, User $user, $expire = 0) public static function create(string $data, string $name, User $user, int $expire = 0): File
{ {
// Get the mimetype // Get the mimetype
$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($data); $mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($data);
@ -91,7 +91,7 @@ class File
* Constructor. * Constructor.
* @param int $fileId * @param int $fileId
*/ */
public function __construct($fileId) public function __construct(int $fileId)
{ {
// Attempt to get the database row // Attempt to get the database row
$fileRow = DB::table('uploads') $fileRow = DB::table('uploads')
@ -113,7 +113,7 @@ class File
/** /**
* Delete this file from the database. * Delete this file from the database.
*/ */
public function delete() public function delete(): void
{ {
$filename = path(config('file.uploads_dir') . $this->id . ".bin"); $filename = path(config('file.uploads_dir') . $this->id . ".bin");

View file

@ -23,7 +23,7 @@ class FileSystem
* Resolves the root path. * Resolves the root path.
* @return string * @return string
*/ */
public static function getRootPath() public static function getRootPath(): string
{ {
if (self::$rootPath === null) { if (self::$rootPath === null) {
// assuming we're running from the 'app' subdirectory // assuming we're running from the 'app' subdirectory
@ -35,18 +35,20 @@ class FileSystem
/** /**
* Fixes a given path to the correct slashes and root. * Fixes a given path to the correct slashes and root.
* @param string $path
* @return string * @return string
*/ */
public static function getPath($path) public static function getPath(string $path): string
{ {
return self::getRootPath() . DIRECTORY_SEPARATOR . self::fixSlashes($path); return self::getRootPath() . DIRECTORY_SEPARATOR . self::fixSlashes($path);
} }
/** /**
* Fixes slashes. * Fixes slashes.
* @param string $path
* @return string * @return string
*/ */
private static function fixSlashes($path) private static function fixSlashes(string $path): string
{ {
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
} }

View file

@ -126,7 +126,7 @@ class Forum
* Gets all subforums of this forum. * Gets all subforums of this forum.
* @return array * @return array
*/ */
public function forums() public function forums(): array
{ {
// Check if forumsCache is populated // Check if forumsCache is populated
if (!count($this->forumsCache)) { if (!count($this->forumsCache)) {
@ -154,7 +154,7 @@ class Forum
* Gets the topics in this forum. * Gets the topics in this forum.
* @return array * @return array
*/ */
public function topics() public function topics(): array
{ {
// Check if topicsCache is populated // Check if topicsCache is populated
if (!count($this->topicsCache)) { if (!count($this->topicsCache)) {
@ -186,7 +186,7 @@ class Forum
* Gets the first post in this forum. * Gets the first post in this forum.
* @return Post * @return Post
*/ */
public function firstPost() public function firstPost(): Post
{ {
// Check if firstPostCache is set // Check if firstPostCache is set
if ($this->firstPostCache === null) { if ($this->firstPostCache === null) {
@ -214,7 +214,7 @@ class Forum
* Gets the last post in this forum. * Gets the last post in this forum.
* @return Post * @return Post
*/ */
public function lastPost() public function lastPost(): Post
{ {
// Check if lastPostCache is set // Check if lastPostCache is set
if ($this->lastPostCache === null) { if ($this->lastPostCache === null) {
@ -242,7 +242,7 @@ class Forum
* Counts the amount of topics in this forum. * Counts the amount of topics in this forum.
* @return int * @return int
*/ */
public function topicCount() public function topicCount(): int
{ {
return DB::table('topics') return DB::table('topics')
->where('forum_id', $this->id) ->where('forum_id', $this->id)
@ -253,7 +253,7 @@ class Forum
* Counts the amount of posts in this forum. * Counts the amount of posts in this forum.
* @return int * @return int
*/ */
public function postCount() public function postCount(): int
{ {
return DB::table('posts') return DB::table('posts')
->where('forum_id', $this->id) ->where('forum_id', $this->id)
@ -265,7 +265,7 @@ class Forum
* @param int $user * @param int $user
* @return bool * @return bool
*/ */
public function unread($user) public function unread(int $user): bool
{ {
// Return false if the user id is less than 1 // Return false if the user id is less than 1
if ($user < 1) { if ($user < 1) {
@ -294,7 +294,7 @@ class Forum
* Update the read status of all topics in this forum at once. * Update the read status of all topics in this forum at once.
* @param int $user * @param int $user
*/ */
public function trackUpdateAll($user) public function trackUpdateAll(int $user): void
{ {
// Iterate over every forum // Iterate over every forum
foreach ($this->forums() as $forum) { foreach ($this->forums() as $forum) {

View file

@ -30,17 +30,17 @@ class ForumPerms
$this->ranks = array_keys($user->ranks); $this->ranks = array_keys($user->ranks);
} }
public function __get($name) public function __get(string $name): bool
{ {
return $this->check($name); return $this->check($name);
} }
public function __isset($name) public function __isset(string $name): bool
{ {
return $this->valid($name); return $this->valid($name);
} }
public function valid($name) public function valid(string $name): bool
{ {
if (!array_key_exists($name, $this->validCache)) { if (!array_key_exists($name, $this->validCache)) {
$column = 'perm_' . camel_to_snake($name); $column = 'perm_' . camel_to_snake($name);
@ -50,7 +50,7 @@ class ForumPerms
return $this->validCache[$name]; return $this->validCache[$name];
} }
public function check($name) public function check(string $name): bool
{ {
if (!array_key_exists($name, $this->permCache)) { if (!array_key_exists($name, $this->permCache)) {
$column = 'perm_' . camel_to_snake($name); $column = 'perm_' . camel_to_snake($name);

View file

@ -101,7 +101,7 @@ class Post
* Constructor. * Constructor.
* @param int $postId * @param int $postId
*/ */
public function __construct($postId) public function __construct(int $postId)
{ {
// Attempt to get the database row // Attempt to get the database row
$postRow = DB::table('posts') $postRow = DB::table('posts')
@ -147,7 +147,7 @@ class Post
* @param int $forum * @param int $forum
* @return Post * @return Post
*/ */
public static function create($subject, $text, User $poster, $topic = 0, $forum = 0) public static function create(string $subject, string $text, User $poster, int $topic = 0, int $forum = 0): Post
{ {
// If no topic is specified create a new one // If no topic is specified create a new one
if ($topic) { if ($topic) {
@ -186,7 +186,7 @@ class Post
* @param bool $ignoreIp * @param bool $ignoreIp
* @return Post * @return Post
*/ */
public function update($ignoreIp = false) public function update(bool $ignoreIp = false): Post
{ {
// Create a topic object // Create a topic object
$topic = new Topic($this->topic); $topic = new Topic($this->topic);
@ -215,7 +215,7 @@ class Post
/** /**
* Undo deletion. * Undo deletion.
*/ */
public function restore() public function restore(): void
{ {
DB::table('posts') DB::table('posts')
->where('post_id', $this->id) ->where('post_id', $this->id)
@ -225,9 +225,9 @@ class Post
} }
/** /**
* delete this. * delet this.
*/ */
public function delete() public function delete(): void
{ {
DB::table('posts') DB::table('posts')
->where('post_id', $this->id) ->where('post_id', $this->id)
@ -237,9 +237,9 @@ class Post
} }
/** /**
* DELETE THIS. * DELET THIS.
*/ */
public function purge() public function purge(): void
{ {
DB::table('posts') DB::table('posts')
->where('post_id', $this->id) ->where('post_id', $this->id)
@ -248,26 +248,21 @@ class Post
/** /**
* Check if a user has read this post before. * Check if a user has read this post before.
* @param mixed $user * @param int $user
* @return bool * @return bool
*/ */
public function unread($user) public function unread(int $user): bool
{ {
// Return false if the user id is less than 1 // Only check if user id is positive
if ($user < 1) { if ($user >= 1) {
return false; // Get track row from the database
}
// Attempt to get track row from the database
$track = DB::table('topics_track') $track = DB::table('topics_track')
->where('user_id', $user) ->where('user_id', $user)
->where('topic_id', $this->topic) ->where('topic_id', $this->topic)
->where('mark_time', '>', $this->time) ->where('mark_time', '>', $this->time)
->count(); ->count();
// If nothing was returned it's obvious that the status is unread return !$track;
if (!$track) {
return true;
} }
// Else just return false meaning everything is read // Else just return false meaning everything is read

View file

@ -108,7 +108,7 @@ class Topic
* Constructor. * Constructor.
* @param int $topicId * @param int $topicId
*/ */
public function __construct($topicId) public function __construct(int $topicId)
{ {
// Attempt to get the database row // Attempt to get the database row
$topicRow = DB::table('topics') $topicRow = DB::table('topics')
@ -139,7 +139,7 @@ class Topic
* @param int $type * @param int $type
* @return Topic * @return Topic
*/ */
public static function create($forum, $title, $status = 0, $type = 0) public static function create(int $forum, string $title, int $status = 0, int $type = 0)
{ {
// Create the database entry // Create the database entry
$id = DB::table('topics') $id = DB::table('topics')
@ -158,7 +158,7 @@ class Topic
/** /**
* Delete the current topic. * Delete the current topic.
*/ */
public function delete() public function delete(): void
{ {
// Delete all posts // Delete all posts
DB::table('posts') DB::table('posts')
@ -176,7 +176,7 @@ class Topic
* @param int $forum * @param int $forum
* @param bool $setOld * @param bool $setOld
*/ */
public function move($forum, $setOld = true) public function move(int $forum, bool $setOld = true): void
{ {
// Update all posts // Update all posts
DB::table('posts') DB::table('posts')
@ -196,7 +196,7 @@ class Topic
* Update the topic data. * Update the topic data.
* @return Topic * @return Topic
*/ */
public function update() public function update(): Topic
{ {
// Update row // Update row
DB::table('topics') DB::table('topics')
@ -219,7 +219,7 @@ class Topic
* Get the replies to this topic. * Get the replies to this topic.
* @return array * @return array
*/ */
public function posts() public function posts(): array
{ {
// Check if postsCache is something // Check if postsCache is something
if (!count($this->postsCache)) { if (!count($this->postsCache)) {
@ -237,19 +237,16 @@ class Topic
} }
$this->postsCache = $posts; $this->postsCache = $posts;
} else {
$posts = $this->postsCache;
} }
// Return the post objects return $this->postsCache;
return $posts;
} }
/** /**
* Get the opening post. * Get the opening post.
* @return Post * @return Post
*/ */
public function firstPost() public function firstPost(): Post
{ {
// Check if the cache var is set // Check if the cache var is set
if ($this->firstPostCache !== null) { if ($this->firstPostCache !== null) {
@ -277,7 +274,7 @@ class Topic
* Get the latest reply. * Get the latest reply.
* @return Post * @return Post
*/ */
public function lastPost() public function lastPost(): Post
{ {
// Check if the cache var is set // Check if the cache var is set
if ($this->lastPostCache !== null) { if ($this->lastPostCache !== null) {
@ -305,7 +302,7 @@ class Topic
* Get the amount of replies. * Get the amount of replies.
* @return int * @return int
*/ */
public function replyCount() public function replyCount(): int
{ {
return DB::table('posts') return DB::table('posts')
->where('topic_id', $this->id) ->where('topic_id', $this->id)
@ -317,23 +314,18 @@ class Topic
* @param int $user * @param int $user
* @return bool * @return bool
*/ */
public function unread($user) public function unread(int $user): bool
{ {
// Return false if the user id is less than 1 // Only check if user id is positive
if ($user < 1) { if ($user >= 1) {
return false; // Get track row from the database
}
// Attempt to get track row from the database
$track = DB::table('topics_track') $track = DB::table('topics_track')
->where('user_id', $user) ->where('user_id', $user)
->where('topic_id', $this->id) ->where('topic_id', $this->id)
->where('mark_time', '>', $this->lastPost()->time) ->where('mark_time', '>', $this->lastPost()->time)
->count(); ->count();
// If nothing was returned it's obvious that the status is unread return !$track;
if (!$track) {
return true;
} }
// Else just return false meaning everything is read // Else just return false meaning everything is read
@ -344,7 +336,7 @@ class Topic
* Update the read status. * Update the read status.
* @param int $user * @param int $user
*/ */
public function trackUpdate($user) public function trackUpdate(int $user): void
{ {
// Check if we already have a track record // Check if we already have a track record
$track = DB::table('topics_track') $track = DB::table('topics_track')
@ -377,7 +369,7 @@ class Topic
/** /**
* Update the view count. * Update the view count.
*/ */
public function viewsUpdate() public function viewsUpdate(): void
{ {
DB::table('topics') DB::table('topics')
->where('topic_id', $this->id) ->where('topic_id', $this->id)
@ -387,7 +379,7 @@ class Topic
/** /**
* Update the timestamp of when this topic was last replied to. * Update the timestamp of when this topic was last replied to.
*/ */
public function lastUpdate() public function lastUpdate(): void
{ {
DB::table('topics') DB::table('topics')
->where('topic_id', $this->id) ->where('topic_id', $this->id)

View file

@ -16,7 +16,7 @@ class EnableCORS implements MiddlewareInterface
/** /**
* Enables CORS. * Enables CORS.
*/ */
public function run() public function run(): void
{ {
if (isset($_SERVER['HTTP_ORIGIN'])) { if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");

View file

@ -18,7 +18,7 @@ class UpdateLastOnline implements MiddlewareInterface
/** /**
* Update the last online information for the active user. * Update the last online information for the active user.
*/ */
public function run() public function run(): void
{ {
if (CurrentSession::$user->id !== 0) { if (CurrentSession::$user->id !== 0) {
CurrentSession::$user->updateOnline(); CurrentSession::$user->updateOnline();

View file

@ -20,7 +20,7 @@ class Net
* Returns the connecting IP. * Returns the connecting IP.
* @return string * @return string
*/ */
public static function ip() public static function ip(): string
{ {
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1'; return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';
} }
@ -30,7 +30,7 @@ class Net
* @param string $ipAddr * @param string $ipAddr
* @return int * @return int
*/ */
public static function detectIPVersion($ipAddr) public static function detectIPVersion(string $ipAddr): int
{ {
// Check if var is IP // Check if var is IP
if (filter_var($ipAddr, FILTER_VALIDATE_IP)) { if (filter_var($ipAddr, FILTER_VALIDATE_IP)) {
@ -55,7 +55,7 @@ class Net
* @throws NetInvalidAddressException * @throws NetInvalidAddressException
* @return string * @return string
*/ */
public static function pton($ip) public static function pton(string $ip): string
{ {
// Detect the IP version // Detect the IP version
$ipv = self::detectIPVersion($ip); $ipv = self::detectIPVersion($ip);
@ -80,7 +80,7 @@ class Net
* @throws NetAddressTypeException * @throws NetAddressTypeException
* @return string * @return string
*/ */
public static function ntop($bin) public static function ntop(string $bin): string
{ {
// Get the length of the binary string // Get the length of the binary string
$len = strlen($bin); $len = strlen($bin);
@ -100,7 +100,7 @@ class Net
* @param string $range * @param string $range
* @return bool * @return bool
*/ */
public static function matchCIDR($ip, $range) public static function matchCIDR(string $ip, string $range): bool
{ {
// Break the range up in parts // Break the range up in parts
list($net, $mask) = explode('/', $range); list($net, $mask) = explode('/', $range);
@ -135,7 +135,7 @@ class Net
* @param string $mask * @param string $mask
* @return bool * @return bool
*/ */
private static function matchCIDRv4($ip, $net, $mask) private static function matchCIDRv4(string $ip, string $net, string $mask): bool
{ {
// Convert IP and Net address to long // Convert IP and Net address to long
$ip = ip2long($ip); $ip = ip2long($ip);
@ -153,7 +153,7 @@ class Net
* @param int $mask * @param int $mask
* @return string * @return string
*/ */
private static function maskToByteArray($mask) private static function maskToByteArray(int $mask): string
{ {
// Generate an address from the mask // Generate an address from the mask
$addr = str_repeat("f", $mask / 4); $addr = str_repeat("f", $mask / 4);
@ -190,7 +190,7 @@ class Net
* @param int $mask * @param int $mask
* @return bool * @return bool
*/ */
private static function matchCIDRv6($ip, $net, $mask) private static function matchCIDRv6(string $ip, string $net, int $mask): bool
{ {
// Pack the IP and Net addresses // Pack the IP and Net addresses
$ip = inet_pton($ip); $ip = inet_pton($ip);
@ -207,10 +207,10 @@ class Net
* Make a web request. * Make a web request.
* @param string $url * @param string $url
* @param string $method * @param string $method
* @param mixed $params * @param mixed $params Can be either an array or a string.
* @return string * @return string
*/ */
public static function request($url, $method = 'GET', $params = null) public static function request(string $url, string $method = 'GET', $params = null): string
{ {
$curl = curl_init(); $curl = curl_init();

View file

@ -25,7 +25,7 @@ class Category
* Constructor. * Constructor.
* @param string $name * @param string $name
*/ */
public function __construct($name) public function __construct(string $name)
{ {
$this->name = $name; $this->name = $name;
} }
@ -33,8 +33,9 @@ class Category
/** /**
* Gets the news posts in this category. * Gets the news posts in this category.
* @param int $limit * @param int $limit
* @return array
*/ */
public function posts($limit = 0) public function posts(int $limit = 0): array
{ {
$postIds = DB::table('news') $postIds = DB::table('news')
->where('news_category', $this->name) ->where('news_category', $this->name)

View file

@ -20,7 +20,7 @@ class Post
/** /**
* The format the comment categories should follow. * The format the comment categories should follow.
*/ */
const COMMENT_CATEGORY_FORMAT = "news-%s-%u"; private const COMMENT_CATEGORY_FORMAT = "news-%s-%u";
/** /**
* The id of this news post. * The id of this news post.
@ -74,7 +74,7 @@ class Post
* Constructor. * Constructor.
* @param int $id * @param int $id
*/ */
public function __construct($id = 0) public function __construct(int $id = 0)
{ {
// Get comment data from the database // Get comment data from the database
$data = DB::table('news') $data = DB::table('news')
@ -95,7 +95,7 @@ class Post
/** /**
* Saving changes to this news post. * Saving changes to this news post.
*/ */
public function save() public function save(): void
{ {
// Create submission data, insert and update take the same format // Create submission data, insert and update take the same format
$data = [ $data = [
@ -120,7 +120,7 @@ class Post
/** /**
* Deleting this news post. * Deleting this news post.
*/ */
public function delete() public function delete(): void
{ {
DB::table('news') DB::table('news')
->where('news_id', $this->id) ->where('news_id', $this->id)
@ -133,7 +133,7 @@ class Post
* Get the user object of the poster. * Get the user object of the poster.
* @return User * @return User
*/ */
public function userData() public function userData(): User
{ {
return User::construct($this->user); return User::construct($this->user);
} }
@ -142,7 +142,7 @@ class Post
* Count the amount of comments this post has. * Count the amount of comments this post has.
* @return int * @return int
*/ */
public function commentCount() public function commentCount(): int
{ {
if (!$this->commentCountCache) { if (!$this->commentCountCache) {
$this->commentCountCache = DB::table('comments') $this->commentCountCache = DB::table('comments')
@ -157,7 +157,7 @@ class Post
* Get the comments on this post. * Get the comments on this post.
* @return array * @return array
*/ */
public function comments() public function comments(): array
{ {
if (!$this->commentsCache) { if (!$this->commentsCache) {
$commentIds = DB::table('comments') $commentIds = DB::table('comments')

View file

@ -71,7 +71,7 @@ class Notification
* The constructor. * The constructor.
* @param int $id * @param int $id
*/ */
public function __construct($id = 0) public function __construct(int $id = 0)
{ {
// Get notification data from the database // Get notification data from the database
$data = DB::table('notifications') $data = DB::table('notifications')
@ -95,7 +95,7 @@ class Notification
/** /**
* Saving changes to this notification. * Saving changes to this notification.
*/ */
public function save() public function save(): void
{ {
// Create submission data, insert and update take the same format // Create submission data, insert and update take the same format
$data = [ $data = [
@ -123,7 +123,7 @@ class Notification
/** /**
* Toggle the read status * Toggle the read status
*/ */
public function toggleRead() public function toggleRead(): void
{ {
// Set read to the negative value of itself // Set read to the negative value of itself
$this->read = !$this->read; $this->read = !$this->read;
@ -133,7 +133,7 @@ class Notification
* Get the user object. * Get the user object.
* @return User * @return User
*/ */
public function userData() public function userData(): User
{ {
return User::construct($this->user); return User::construct($this->user);
} }

View file

@ -32,28 +32,21 @@ class Payments
/** /**
* Initialise the wrapper. * Initialise the wrapper.
* @return bool
*/ */
public static function init() public static function init(): void
{ {
// Set PayPal object // Set PayPal object
try {
self::$paypal = new \PayPal\Rest\ApiContext( self::$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential( new \PayPal\Auth\OAuthTokenCredential(
config("paypal.client_id"), config("paypal.client_id"),
config("paypal.secret_id") config("paypal.secret_id")
) )
); );
} catch (\Exception $e) {
return false;
}
// Set the configuration // Set the configuration
self::$paypal->setConfig([ self::$paypal->setConfig([
'mode' => config("paypal.mode"), 'mode' => config("paypal.mode"),
]); ]);
return true;
} }
/** /**
@ -62,9 +55,9 @@ class Payments
* @param string $itemName * @param string $itemName
* @param string $transDescription * @param string $transDescription
* @param string $returnUrl * @param string $returnUrl
* @return bool|null|string * @return string
*/ */
public static function createTransaction($total, $itemName, $transDescription, $returnUrl) public static function createTransaction(float $total, string $itemName, string $transDescription, string $returnUrl): string
{ {
// Create the payer object // Create the payer object
$payer = new Payer(); $payer = new Payer();
@ -130,7 +123,7 @@ class Payments
try { try {
$payment->create(self::$paypal); $payment->create(self::$paypal);
} catch (\Exception $ex) { } catch (\Exception $ex) {
return false; return route('premium.error');
} }
// Return the approval link if everything is gucci // Return the approval link if everything is gucci
@ -143,7 +136,7 @@ class Payments
* @param string $payerId * @param string $payerId
* @return bool * @return bool
*/ */
public static function completeTransaction($paymentId, $payerId) public static function completeTransaction(string $paymentId, string $payerId): bool
{ {
// Attempt to get the payment // Attempt to get the payment
$payment = Payment::get($paymentId, self::$paypal); $payment = Payment::get($paymentId, self::$paypal);

View file

@ -1,13 +1,13 @@
<?php <?php
/** /**
* Holds the global permissions handler. * Holds the old permissions handler, only still here for reference while fixing the forum permission backend.
* @package Sakura * @package Sakura
*/ */
namespace Sakura; namespace Sakura;
/** /**
* Global permissions handler. * Old permissions handler.
* @package Sakura * @package Sakura
* @author Julian van de Groep <me@flash.moe> * @author Julian van de Groep <me@flash.moe>
*/ */

View file

@ -59,7 +59,7 @@ class Rank
* Indicates if this rank should be hidden. * Indicates if this rank should be hidden.
* @var bool * @var bool
*/ */
private $hidden = true; public $hidden = true;
/** /**
* Instance cache container. * Instance cache container.
@ -73,7 +73,7 @@ class Rank
* @param bool $forceRefresh * @param bool $forceRefresh
* @return Rank * @return Rank
*/ */
public static function construct($rid, $forceRefresh = false) public static function construct(int $rid, bool $forceRefresh = false): Rank
{ {
// Check if a rank object isn't present in cache // Check if a rank object isn't present in cache
if ($forceRefresh || !array_key_exists($rid, self::$rankCache)) { if ($forceRefresh || !array_key_exists($rid, self::$rankCache)) {
@ -89,7 +89,7 @@ class Rank
* Constructor. * Constructor.
* @param int $rankId * @param int $rankId
*/ */
private function __construct($rankId) private function __construct(int $rankId)
{ {
// Get the rank database row // Get the rank database row
$rankRow = DB::table('ranks') $rankRow = DB::table('ranks')
@ -114,26 +114,17 @@ class Rank
* @param bool $multi * @param bool $multi
* @return string * @return string
*/ */
public function name($multi = false) public function name(bool $multi = false): string
{ {
return $this->name . ($multi ? $this->multiple : null); return $this->name . ($multi ? $this->multiple : null);
} }
/**
* Indicates if the rank is hidden.
* @return bool
*/
public function hidden()
{
return $this->hidden;
}
/** /**
* Returns all users that are part of this rank. * Returns all users that are part of this rank.
* @param bool $justIds * @param bool $justIds
* @return array * @return array
*/ */
public function users($justIds = false) public function users(bool $justIds = false): array
{ {
// Fetch all users part of this rank // Fetch all users part of this rank
$get = DB::table('user_ranks') $get = DB::table('user_ranks')

View file

@ -10,6 +10,7 @@ use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException; use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
use Phroute\Phroute\Exception\HttpRouteNotFoundException; use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\RouteCollector; use Phroute\Phroute\RouteCollector;
use Closure;
/** /**
* Sakura Wrapper for Phroute. * Sakura Wrapper for Phroute.
@ -24,12 +25,6 @@ class Router
*/ */
protected static $router = null; protected static $router = null;
/**
* Base path of the router.
* @var string
*/
protected static $basePath = null;
/** /**
* Container for the Dispatcher. * Container for the Dispatcher.
* @var Dispatcher * @var Dispatcher
@ -56,7 +51,7 @@ class Router
* @param string $name * @param string $name
* @param array $args * @param array $args
*/ */
public static function __callStatic($name, $args) public static function __callStatic(string $name, array $args): void
{ {
// Check if the method exists // Check if the method exists
if (in_array($name = strtoupper($name), self::$methods)) { if (in_array($name = strtoupper($name), self::$methods)) {
@ -82,32 +77,18 @@ class Router
/** /**
* Initialisation. * Initialisation.
* @param string $basePath
*/ */
public static function init($basePath = '/') public static function init(): void
{ {
// Set base path
self::setBasePath($basePath);
// Create router
self::$router = new RouteCollector; self::$router = new RouteCollector;
} }
/**
* Set the base path.
* @param string $basePath
*/
public static function setBasePath($basePath)
{
self::$basePath = $basePath;
}
/** /**
* Parse a URL. * Parse a URL.
* @param string $url * @param string $url
* @return string * @return string
*/ */
private static function parseUrl($url) private static function parseUrl(string $url): string
{ {
return parse_url($url, PHP_URL_PATH); return parse_url($url, PHP_URL_PATH);
} }
@ -118,7 +99,7 @@ class Router
* @param string|array $args * @param string|array $args
* @return string * @return string
*/ */
public static function route($name, $args = null) public static function route(string $name, $args = null): string
{ {
// Array-ify the arguments // Array-ify the arguments
if ($args !== null && !is_array($args)) { if ($args !== null && !is_array($args)) {
@ -127,15 +108,15 @@ class Router
$args[] = $temp; $args[] = $temp;
} }
return self::$basePath . self::$router->route($name, $args); return '/' . self::$router->route($name, $args);
} }
/** /**
* Create group. * Create group.
* @param array $filters * @param array $filters
* @param \Closure $callback * @param Closure $callback
*/ */
public static function group($filters, $callback) public static function group(array $filters, Closure $callback): void
{ {
// Execute the inner function // Execute the inner function
self::$router->group($filters, $callback); self::$router->group($filters, $callback);
@ -144,9 +125,9 @@ class Router
/** /**
* Create filter. * Create filter.
* @param string $name * @param string $name
* @param \Closure $method * @param Closure $method
*/ */
public static function filter($name, $method) public static function filter(string $name, Closure $method): void
{ {
self::$router->filter($name, $method); self::$router->filter($name, $method);
} }
@ -155,9 +136,9 @@ class Router
* Handle requests. * Handle requests.
* @param string $method * @param string $method
* @param string $url * @param string $url
* @return mixed * @return string
*/ */
public static function handle($method, $url) public static function handle(string $method, string $url): string
{ {
// Check if the dispatcher is defined // Check if the dispatcher is defined
if (self::$dispatcher === null) { if (self::$dispatcher === null) {

View file

@ -106,7 +106,7 @@ class Session
* @param int $length * @param int $length
* @return Session * @return Session
*/ */
public static function create($user, $ip, $country, $agent = null, $remember = false, $length = 604800) public static function create(int $user, string $ip, string $country, string $agent = null, bool $remember = false, int $length = 604800)
{ {
$start = time(); $start = time();
$key = bin2hex(random_bytes(64)); $key = bin2hex(random_bytes(64));
@ -129,7 +129,7 @@ class Session
/** /**
* Delete this session. * Delete this session.
*/ */
public function delete() public function delete(): void
{ {
DB::table('sessions') DB::table('sessions')
->where('session_id', $this->id) ->where('session_id', $this->id)
@ -142,7 +142,7 @@ class Session
* @param string $ip * @param string $ip
* @return bool * @return bool
*/ */
public function validate($user, $ip = null) public function validate(int $user, string $ip = null): bool
{ {
// Get session from database // Get session from database
$session = DB::table('sessions') $session = DB::table('sessions')
@ -184,7 +184,7 @@ class Session
* @param bool $long * @param bool $long
* @return string * @return string
*/ */
public function country($long = false) public function country(bool $long = false): string
{ {
return $long ? get_country_name($this->country) : $this->country; return $long ? get_country_name($this->country) : $this->country;
} }

View file

@ -22,12 +22,12 @@ class Template
/** /**
* The file extension used by template files. * The file extension used by template files.
*/ */
const FILE_EXT = '.twig'; private const FILE_EXT = '.twig';
/** /**
* The path relative to the root. * The path relative to the root.
*/ */
const VIEWS_DIR = 'resources/views/'; private const VIEWS_DIR = 'resources/views/';
/** /**
* The template name. * The template name.
@ -82,7 +82,7 @@ class Template
/** /**
* Initialise the templating engine. * Initialise the templating engine.
*/ */
public static function init() public static function init(): void
{ {
$views_dir = path(self::VIEWS_DIR); $views_dir = path(self::VIEWS_DIR);
@ -130,7 +130,7 @@ class Template
* Checks if twig is available. * Checks if twig is available.
* @return bool * @return bool
*/ */
public static function available() public static function available(): bool
{ {
return self::$engine !== null && self::$name !== null; return self::$engine !== null && self::$name !== null;
} }
@ -139,7 +139,7 @@ class Template
* Merge the parse variables. * Merge the parse variables.
* @param array $vars * @param array $vars
*/ */
public static function vars($vars) public static function vars(array $vars): void
{ {
self::$vars = array_merge(self::$vars, $vars); self::$vars = array_merge(self::$vars, $vars);
} }
@ -149,16 +149,17 @@ class Template
* @param string $file * @param string $file
* @return string * @return string
*/ */
public static function render($file) public static function render(string $file): string
{ {
return self::$engine->render($file . self::FILE_EXT, self::$vars); return self::$engine->render($file . self::FILE_EXT, self::$vars);
} }
/** /**
* Checks if a template directory exists. * Checks if a template directory exists.
* @param string $name
* @return bool * @return bool
*/ */
public static function exists($name) public static function exists(string $name): bool
{ {
return ctype_alnum($name) && file_exists(path(self::VIEWS_DIR . $name . "/")); return ctype_alnum($name) && file_exists(path(self::VIEWS_DIR . $name . "/"));
} }

View file

@ -1,16 +0,0 @@
<?php
/**
* Holds the extension manager.
* @package Sakura
*/
namespace Sakura;
/**
* Extension manager.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Trick
{
}

View file

@ -278,7 +278,7 @@ class User
* @param bool $forceRefresh * @param bool $forceRefresh
* @return User * @return User
*/ */
public static function construct($uid, $forceRefresh = false) public static function construct($uid, bool $forceRefresh = false): User
{ {
// Check if a user object isn't present in cache // Check if a user object isn't present in cache
if ($forceRefresh || !array_key_exists($uid, self::$userCache)) { if ($forceRefresh || !array_key_exists($uid, self::$userCache)) {
@ -298,7 +298,7 @@ class User
* @param array $ranks * @param array $ranks
* @return User * @return User
*/ */
public static function create($username, $password, $email, $ranks = [2]) public static function create(string $username, string $password, string $email, array $ranks = [2]): User
{ {
// Set a few variables // Set a few variables
$usernameClean = clean_string($username, true); $usernameClean = clean_string($username, true);
@ -450,7 +450,7 @@ class User
* Get a Carbon object of the registration date. * Get a Carbon object of the registration date.
* @return Carbon * @return Carbon
*/ */
public function registerDate() public function registerDate(): Carbon
{ {
return Carbon::createFromTimestamp($this->registered); return Carbon::createFromTimestamp($this->registered);
} }
@ -459,7 +459,7 @@ class User
* Get a Carbon object of the last online date. * Get a Carbon object of the last online date.
* @return Carbon * @return Carbon
*/ */
public function lastDate() public function lastDate(): Carbon
{ {
return Carbon::createFromTimestamp($this->lastOnline); return Carbon::createFromTimestamp($this->lastOnline);
} }
@ -469,7 +469,7 @@ class User
* @param bool $age * @param bool $age
* @return int|string * @return int|string
*/ */
public function birthday($age = false) public function birthday(bool $age = false)
{ {
// If age is requested calculate it // If age is requested calculate it
if ($age) { if ($age) {
@ -493,7 +493,7 @@ class User
* @param bool $long * @param bool $long
* @return string * @return string
*/ */
public function country($long = false) public function country(bool $long = false): string
{ {
return $long ? get_country_name($this->country) : $this->country; return $long ? get_country_name($this->country) : $this->country;
} }
@ -502,7 +502,7 @@ class User
* Check if a user is online. * Check if a user is online.
* @return bool * @return bool
*/ */
public function isOnline() public function isOnline(): bool
{ {
// Count sessions // Count sessions
$sessions = DB::table('sessions') $sessions = DB::table('sessions')
@ -521,7 +521,7 @@ class User
/** /**
* Updates the last IP and online time of the user. * Updates the last IP and online time of the user.
*/ */
public function updateOnline() public function updateOnline(): void
{ {
$this->lastOnline = time(); $this->lastOnline = time();
$this->lastIp = Net::ip(); $this->lastIp = Net::ip();
@ -538,7 +538,7 @@ class User
* Runs some checks to see if this user is activated. * Runs some checks to see if this user is activated.
* @return bool * @return bool
*/ */
public function isActive() public function isActive(): bool
{ {
return $this->id !== 0 && $this->activated; return $this->id !== 0 && $this->activated;
} }
@ -547,7 +547,7 @@ class User
* Get a few forum statistics. * Get a few forum statistics.
* @return array * @return array
*/ */
public function forumStats() public function forumStats(): array
{ {
$posts = DB::table('posts') $posts = DB::table('posts')
->where('poster_id', $this->id) ->where('poster_id', $this->id)
@ -559,17 +559,14 @@ class User
->groupBy('topic_id') ->groupBy('topic_id')
->count(); ->count();
return [ return compact('posts', 'topics');
'posts' => $posts,
'topics' => $topics,
];
} }
/** /**
* Add ranks to a user. * Add ranks to a user.
* @param array $ranks * @param array $ranks
*/ */
public function addRanks($ranks) public function addRanks(array $ranks): void
{ {
// Update the ranks array // Update the ranks array
$ranks = array_diff( $ranks = array_diff(
@ -598,7 +595,7 @@ class User
* Remove a set of ranks from a user. * Remove a set of ranks from a user.
* @param array $ranks * @param array $ranks
*/ */
public function removeRanks($ranks) public function removeRanks(array $ranks): void
{ {
// Current ranks // Current ranks
$remove = array_intersect(array_keys($this->ranks), $ranks); $remove = array_intersect(array_keys($this->ranks), $ranks);
@ -618,7 +615,7 @@ class User
* Change the main rank of a user. * Change the main rank of a user.
* @param int $rank * @param int $rank
*/ */
public function setMainRank($rank) public function setMainRank(int $rank): void
{ {
$this->mainRankId = $rank; $this->mainRankId = $rank;
$this->mainRank = $this->ranks[$rank]; $this->mainRank = $this->ranks[$rank];
@ -635,7 +632,7 @@ class User
* @param array $ranks * @param array $ranks
* @return bool * @return bool
*/ */
public function hasRanks($ranks) public function hasRanks(array $ranks): bool
{ {
// Check if the main rank is the specified rank // Check if the main rank is the specified rank
if (in_array($this->mainRankId, $ranks)) { if (in_array($this->mainRankId, $ranks)) {
@ -658,7 +655,7 @@ class User
* Add a new friend. * Add a new friend.
* @param int $uid * @param int $uid
*/ */
public function addFriend($uid) public function addFriend(int $uid): void
{ {
// Add friend // Add friend
DB::table('friends') DB::table('friends')
@ -674,7 +671,7 @@ class User
* @param int $uid * @param int $uid
* @param bool $deleteRequest * @param bool $deleteRequest
*/ */
public function removeFriend($uid, $deleteRequest = false) public function removeFriend(int $uid, bool $deleteRequest = false): void
{ {
// Remove friend // Remove friend
DB::table('friends') DB::table('friends')
@ -697,7 +694,7 @@ class User
* @param int $with * @param int $with
* @return int * @return int
*/ */
public function isFriends($with) public function isFriends(int $with): int
{ {
// Accepted from this user // Accepted from this user
$user = DB::table('friends') $user = DB::table('friends')
@ -727,7 +724,7 @@ class User
* @param bool $noObj * @param bool $noObj
* @return array * @return array
*/ */
public function friends($level = 0, $noObj = false) public function friends(int $level = 0, bool $noObj = false): array
{ {
// User ID container // User ID container
$users = []; $users = [];
@ -821,7 +818,7 @@ class User
* Get the comments from the user's profile. * Get the comments from the user's profile.
* @return array * @return array
*/ */
public function profileComments() public function profileComments(): array
{ {
$commentIds = DB::table('comments') $commentIds = DB::table('comments')
->where('comment_category', "profile-{$this->id}") ->where('comment_category', "profile-{$this->id}")
@ -844,7 +841,7 @@ class User
* @param int $seconds * @param int $seconds
* @return int * @return int
*/ */
public function addPremium($seconds) public function addPremium(int $seconds): int
{ {
// Check if there's already a record of premium for this user in the database // Check if there's already a record of premium for this user in the database
$getUser = DB::table('premium') $getUser = DB::table('premium')
@ -879,7 +876,7 @@ class User
* Does this user have premium? * Does this user have premium?
* @return int * @return int
*/ */
public function isPremium() public function isPremium(): int
{ {
// Get rank IDs from the db // Get rank IDs from the db
$premiumRank = (int) config('rank.premium'); $premiumRank = (int) config('rank.premium');
@ -917,7 +914,7 @@ class User
* Gets the start and end date of this user's premium tag. * Gets the start and end date of this user's premium tag.
* @return stdClass * @return stdClass
*/ */
public function premiumInfo() public function premiumInfo(): stdClass
{ {
// Attempt to retrieve the premium record from the database // Attempt to retrieve the premium record from the database
$check = DB::table('premium') $check = DB::table('premium')
@ -937,7 +934,7 @@ class User
* Parse the user's userpage. * Parse the user's userpage.
* @return string * @return string
*/ */
public function userPage() public function userPage(): string
{ {
return BBCode\Parser::toHTML(htmlentities($this->page), $this); return BBCode\Parser::toHTML(htmlentities($this->page), $this);
} }
@ -946,7 +943,7 @@ class User
* Parse a user's signature. * Parse a user's signature.
* @return string * @return string
*/ */
public function signature() public function signature(): string
{ {
return BBCode\Parser::toHTML(htmlentities($this->signature), $this); return BBCode\Parser::toHTML(htmlentities($this->signature), $this);
} }
@ -955,7 +952,7 @@ class User
* Get a user's username history. * Get a user's username history.
* @return array * @return array
*/ */
public function getUsernameHistory() public function getUsernameHistory(): array
{ {
return DB::table('username_history') return DB::table('username_history')
->where('user_id', $this->id) ->where('user_id', $this->id)
@ -967,7 +964,7 @@ class User
* Alter the user's username. * Alter the user's username.
* @param string $username * @param string $username
*/ */
public function setUsername($username) public function setUsername(string $username): void
{ {
$username_clean = clean_string($username, true); $username_clean = clean_string($username, true);
@ -996,7 +993,7 @@ class User
* Alter a user's e-mail address. * Alter a user's e-mail address.
* @param string $email * @param string $email
*/ */
public function setMail($email) public function setMail(string $email): void
{ {
$this->email = $email; $this->email = $email;
@ -1011,7 +1008,7 @@ class User
* Change the user's password. * Change the user's password.
* @param string $password * @param string $password
*/ */
public function setPassword($password) public function setPassword(string $password): void
{ {
// Create hash // Create hash
$this->password = password_hash($password, PASSWORD_BCRYPT); $this->password = password_hash($password, PASSWORD_BCRYPT);
@ -1030,7 +1027,7 @@ class User
* Check if password expired. * Check if password expired.
* @return bool * @return bool
*/ */
public function passwordExpired() public function passwordExpired(): bool
{ {
return strlen($this->password) < 1; return strlen($this->password) < 1;
} }
@ -1040,7 +1037,7 @@ class User
* @param string $password * @param string $password
* @return bool * @return bool
*/ */
public function verifyPassword($password) public function verifyPassword(string $password): bool
{ {
return password_verify($password, $this->password); return password_verify($password, $this->password);
} }
@ -1051,7 +1048,7 @@ class User
* @param bool $excludeRead * @param bool $excludeRead
* @return array * @return array
*/ */
public function notifications($timeDifference = 0, $excludeRead = true) public function notifications(int $timeDifference = 0, bool $excludeRead = true): array
{ {
$alertIds = DB::table('notifications') $alertIds = DB::table('notifications')
->where('user_id', $this->id); ->where('user_id', $this->id);
@ -1077,7 +1074,7 @@ class User
/** /**
* Invalidate all sessions related to this user. * Invalidate all sessions related to this user.
*/ */
public function purgeSessions() public function purgeSessions(): void
{ {
DB::table('sessions') DB::table('sessions')
->where('user_id', $this->id) ->where('user_id', $this->id)
@ -1088,7 +1085,7 @@ class User
* Get all a user's sessions * Get all a user's sessions
* @return array * @return array
*/ */
public function sessions() public function sessions(): array
{ {
$sessions = []; $sessions = [];
$ids = array_column(DB::table('sessions') $ids = array_column(DB::table('sessions')
@ -1106,16 +1103,16 @@ class User
* Gets the user's selected design. * Gets the user's selected design.
* @return string * @return string
*/ */
public function design() public function design(): string
{ {
return Template::exists($this->design) ? $this->design : config('general.design'); return isset($this->design) && Template::exists($this->design) ? $this->design : config('general.design');
} }
/** /**
* Gets the user's proper (highest) hierarchy. * Gets the user's proper (highest) hierarchy.
* @return int * @return int
*/ */
public function hierarchy() public function hierarchy(): int
{ {
return DB::table('ranks') return DB::table('ranks')
->join('user_ranks', 'ranks.rank_id', '=', 'user_ranks.rank_id') ->join('user_ranks', 'ranks.rank_id', '=', 'user_ranks.rank_id')
@ -1126,7 +1123,7 @@ class User
/** /**
* Update last listened data. * Update last listened data.
*/ */
public function updateLastTrack() public function updateLastTrack(): void
{ {
if (strlen($this->lastfm) < 1 if (strlen($this->lastfm) < 1
|| $this->musicCheck + config('user.music_update') > time()) { || $this->musicCheck + config('user.music_update') > time()) {

View file

@ -25,17 +25,17 @@ class UserPerms
$this->ranks = array_keys($user->ranks); $this->ranks = array_keys($user->ranks);
} }
public function __get($name) public function __get(string $name): bool
{ {
return $this->check($name); return $this->check($name);
} }
public function __isset($name) public function __isset(string $name): bool
{ {
return $this->valid($name); return $this->valid($name);
} }
public function valid($name) public function valid(string $name): bool
{ {
if (!array_key_exists($name, $this->validCache)) { if (!array_key_exists($name, $this->validCache)) {
$column = 'perm_' . camel_to_snake($name); $column = 'perm_' . camel_to_snake($name);
@ -45,7 +45,7 @@ class UserPerms
return $this->validCache[$name]; return $this->validCache[$name];
} }
public function check($name) public function check(string $name): bool
{ {
if (!array_key_exists($name, $this->permCache)) { if (!array_key_exists($name, $this->permCache)) {
$column = 'perm_' . camel_to_snake($name); $column = 'perm_' . camel_to_snake($name);

View file

@ -9,13 +9,13 @@
Frequently Asked Questions Frequently Asked Questions
</div> </div>
<div class="settings__navigation"> <div class="settings__navigation">
{% for question in page.questions %} {% for question in questions %}
<a href="#{{ question.faq_shorthand }}" class="settings__navigation-link">{{ question.faq_question }}</a> <a href="#{{ question.faq_shorthand }}" class="settings__navigation-link">{{ question.faq_question }}</a>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
<div class="content--left"> <div class="content--left">
{% for question in page.questions %} {% for question in questions %}
<div class="content__header" id="{{ question.faq_shorthand }}"> <div class="content__header" id="{{ question.faq_shorthand }}">
{{ question.faq_question }} {{ question.faq_question }}
<a href="#{{ question.faq_shorthand }}" class="fa fa-quote-right news-rss default"></a> <a href="#{{ question.faq_shorthand }}" class="fa fa-quote-right news-rss default"></a>

View file

@ -194,13 +194,13 @@ Router::group(['before' => 'maintenance'], function () {
// Settings // Settings
Router::group(['prefix' => 'settings'], function () { Router::group(['prefix' => 'settings'], function () {
Router::get('/', function () { Router::get('/', function () {
redirect(route('settings.account.profile')); return redirect(route('settings.account.profile'));
}, 'settings.index'); }, 'settings.index');
// Account section // Account section
Router::group(['prefix' => 'account'], function () { Router::group(['prefix' => 'account'], function () {
Router::get('/', function () { Router::get('/', function () {
redirect(route('settings.account.profile')); return redirect(route('settings.account.profile'));
}); });
Router::get('/profile', 'Settings.AccountController@profile', 'settings.account.profile'); Router::get('/profile', 'Settings.AccountController@profile', 'settings.account.profile');
@ -218,7 +218,7 @@ Router::group(['before' => 'maintenance'], function () {
// Friends section // Friends section
Router::group(['prefix' => 'friends'], function () { Router::group(['prefix' => 'friends'], function () {
Router::get('/', function () { Router::get('/', function () {
redirect(route('settings.account.listing')); return redirect(route('settings.account.listing'));
}); });
Router::get('/listing', 'Settings.FriendsController@listing', 'settings.friends.listing'); Router::get('/listing', 'Settings.FriendsController@listing', 'settings.friends.listing');
@ -228,7 +228,7 @@ Router::group(['before' => 'maintenance'], function () {
// Advanced section // Advanced section
Router::group(['prefix' => 'advanced'], function () { Router::group(['prefix' => 'advanced'], function () {
Router::get('/', function () { Router::get('/', function () {
redirect(route('settings.account.sessions')); return redirect(route('settings.account.sessions'));
}); });
Router::get('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions'); Router::get('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions');
@ -241,13 +241,13 @@ Router::group(['before' => 'maintenance'], function () {
// Settings // Settings
Router::group(['prefix' => 'manage'], function () { Router::group(['prefix' => 'manage'], function () {
Router::get('/', function () { Router::get('/', function () {
redirect(route('manage.overview.index')); return redirect(route('manage.overview.index'));
}, 'manage.index'); }, 'manage.index');
// Overview section // Overview section
Router::group(['prefix' => 'overview'], function () { Router::group(['prefix' => 'overview'], function () {
Router::get('/', function () { Router::get('/', function () {
redirect(route('manage.overview.index')); return redirect(route('manage.overview.index'));
}); });
Router::get('/index', 'Manage.OverviewController@index', 'manage.overview.index'); Router::get('/index', 'Manage.OverviewController@index', 'manage.overview.index');

View file

@ -91,6 +91,7 @@ function redirect($url)
{ {
header("Turbolinks-Location: {$url}"); header("Turbolinks-Location: {$url}");
header("Location: {$url}"); header("Location: {$url}");
return $url;
} }
function check_mx_record($email) function check_mx_record($email)