Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.gitattributes export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpstan.neon export-ignore
/rector.php export-ignore
4 changes: 3 additions & 1 deletion .github/workflows/tests_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
- name: "CS Check"
run: "vendor/bin/php-cs-fixer fix --dry-run --diff"
- name: "Code analyze"
run: "vendor/bin/phpstan"
run: |
vendor/bin/phpstan
vendor/bin/rector process --dry-run
- name: "Run test suite"
run: "vendor/bin/phpunit"
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"require-dev": {
"codeigniter/coding-standard": "^1.8",
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^2.1"
"phpstan/phpstan": "^2.1",
"rector/rector": "^2.0"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ parameters:
paths:
- src
- tests
level: 5
level: 6
bootstrapFiles:
- vendor/codeigniter4/framework/system/Test/bootstrap.php

14 changes: 14 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets()
->withPreparedSets(deadCode: true, codeQuality: true)
->withImportNames();
9 changes: 8 additions & 1 deletion src/Commands/PageCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ class PageCreateCommand extends BaseCommand
protected $name = 'page:create'; // Nama command
protected $description = 'Create a new page router';

/**
* @param list<string> $params
*/
public function run(array $params)
{
if (empty($params)) {
if ($params === []) {
CLI::error('Please specify the page name.');

return;
Expand Down Expand Up @@ -67,6 +70,10 @@ public function run(array $params)

/**
* Create a file from a template, replacing placeholders.
*
* @param array<string, string> $replacements
*
* @return void
*/
private function createFileFromTemplate(string $templateFile, string $targetFile, array $replacements)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

class Services extends BaseService
{
/**
* @return PageRouter
*/
public static function router(?RouteCollectionInterface $routes = null, ?Request $request = null, bool $getShared = true)
{
if ($getShared) {
Expand Down
12 changes: 7 additions & 5 deletions src/Helpers/pageview_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
use Config\View;

if (! function_exists('pageView')) {
/**
* @param array<string, mixed> $data
* @param array<string, mixed> $options
*/
function pageView(string $name, array $data = [], array $options = []): string
{
$config = config(View::class);
Expand Down Expand Up @@ -45,13 +49,11 @@ function asset_url(string $filePath): string
$fullFilePath = FCPATH . $filePath;

// Check if file exists
if (file_exists($fullFilePath)) {
$version = file_exists($fullFilePath)
// Add file modification time as version
$version = filemtime($fullFilePath);
} else {
? filemtime($fullFilePath)
// Fallback version (current timestamp if file doesn't exist)
$version = time();
}
: time();

// Generate full URL with version
return base_url($filePath) . '?v=' . $version;
Expand Down
7 changes: 2 additions & 5 deletions src/PageRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\Exceptions\BadRequestException;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Router\Router;

/**
* Page based router.
*
* This class extends the CodeIgniter's Router class
* to handle page based routes.
*
* @property-read RouteCollection $collection
*/
class PageRouter extends Router
{
Expand Down Expand Up @@ -71,7 +68,7 @@ public function pageBasedRoute(string $uri)
$uri = trim($uri, '/');

// Set default page for root uri
if (empty($uri)) {
if ($uri === '' || $uri === '0') {
$uri = config('App')->defaultPage ?? 'home';
}

Expand All @@ -83,7 +80,7 @@ public function pageBasedRoute(string $uri)

$uriSegments = explode('/', $uri);

while (count($uriSegments) > 0) {
while ($uriSegments !== []) {
$folderPath = $pagesPath . '/' . str_replace('/', DIRECTORY_SEPARATOR, implode('/', $uriSegments));
if (is_dir($folderPath) && file_exists($folderPath . '/' . $controllerName . '.php')) {
$uri = implode('/', $uriSegments);
Expand Down
2 changes: 1 addition & 1 deletion tests/Helpers/PageViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class PageViewTest extends TestCase
{
public function testPageView()
public function testPageView(): void
{
helper('Yllumi\Ci4Pages\Helpers\pageview');

Expand Down
Loading