Add strict typing to all files that were missing it. (#60)
Shockingly, this didn't require any code changes. But PHP is more forgiving with "strict typing" than I'd expected. I may go back and clean up function declarations later, but that's not urgent. Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/60 Co-authored-by: Greg Sarjeant <greg@subcultureofone.org> Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
This commit is contained in:
		
							parent
							
								
									1337ffa155
								
							
						
					
					
						commit
						6123757c37
					
				| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| // This is the initialization code that needs to be run before anything else.
 | ||||
| // - define paths
 | ||||
| // - set up autoloader
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| /* | ||||
|  *  Initialize fundamental configuration | ||||
|  */ | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class AdminController extends Controller { | ||||
|     // GET handler
 | ||||
|     // render the admin page
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class AuthController extends Controller { | ||||
|     function showLogin(?string $error = null){ | ||||
|         global $app; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class Controller { | ||||
|     // Renders the requested template inside templates/main/php
 | ||||
|     protected function render(string $childTemplateFile, array $vars = []) { | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class CssController extends Controller { | ||||
|     public function index() { | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
|     class EmojiController extends Controller { | ||||
|         // Shows the custom emoji management page
 | ||||
|         public function index(){ | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class FeedController extends Controller { | ||||
|     private $ticks; | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class HomeController extends Controller { | ||||
|     // GET handler
 | ||||
|     // renders the homepage view.
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class LogController extends Controller { | ||||
|     private string $storageDir; | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
|     class MoodController extends Controller { | ||||
|         public function index(){ | ||||
|             global $app; | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class TickController extends Controller{ | ||||
|     public function index(int $id){ | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class AtomGenerator extends FeedGenerator { | ||||
|     public function generate(): string { | ||||
|         $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| // Abstract base class for feeds.
 | ||||
| // Specific feeds (RSS, Atom, etc.) will inherit from this.
 | ||||
| // This will wrap the basic generator functionality.
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class RssGenerator extends FeedGenerator { | ||||
|     public function generate(): string { | ||||
|         $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class Log { | ||||
|     const LEVELS = [ | ||||
|         'DEBUG' => 1, | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class Migrator{ | ||||
|     public function __construct(private PDO $db) {} | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| /** | ||||
|  * tkr Prerequisites Checker | ||||
|  * | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| // Very simple router class
 | ||||
| class Router { | ||||
|     // Define the recognized routes.
 | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class Session { | ||||
|     // These can all just be static functions
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class Util { | ||||
|     public static function getClientIp() { | ||||
|         return $_SERVER['HTTP_CLIENT_IP'] ?? | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class ConfigModel { | ||||
|     // properties and default values
 | ||||
|     public string $siteTitle = 'My tkr'; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class CssModel { | ||||
|     public function __construct(private PDO $db) {} | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| // welp this model is overkill
 | ||||
| class EmojiModel{ | ||||
|     public function __construct(private PDO $db) {} | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class TickModel { | ||||
|     public function __construct(private PDO $db, private ConfigModel $config) {} | ||||
|      | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class UserModel { | ||||
|     // properties
 | ||||
|     public string $username = ''; | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class FlashView { | ||||
|     public function renderFlashSection(array $flashMessages): string { | ||||
|         ob_start(); | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class MoodView { | ||||
|     private function render_emoji_groups(array $emojiGroups, string $currentMood): string { | ||||
|         $selected_emoji = $currentMood;  //user->mood;
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| class TicksView { | ||||
|     private $html; | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| require_once dirname(dirname(dirname(__DIR__))) . "/config/bootstrap.php"; | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class FeedControllerTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class HomeControllerTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class LogControllerTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class TickControllerTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class AtomGeneratorTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class FeedGeneratorTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class RssGeneratorTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| 
 | ||||
| class LogTest extends TestCase | ||||
|  | ||||
| @ -1,4 +1,6 @@ | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use PHPUnit\Framework\Attributes\DataProvider; | ||||
| 
 | ||||
|  | ||||
| @ -1,5 +1,7 @@ | ||||
| #!/usr/bin/env php
 | ||||
| <?php | ||||
| declare(strict_types=1); | ||||
| 
 | ||||
| /** | ||||
|  * tkr Setup Script | ||||
|  * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user