Skip to content
/ skeleton-php Public template

A skeleton for modern PHP development, providing a clean structure and essential tooling.

License

Notifications You must be signed in to change notification settings

royrakesh/skeleton-php

Repository files navigation

Skeleton PHP

PHP Skeleton GitHub Actions Workflow Status

A skeleton for modern PHP development, providing a clean structure and essential tooling.

🚀 Features

  • PSR-4 autoloading
  • Pest for testing
  • Laravel Pint for code formatting
  • PHPStan for static analysis
  • Rector for code refactorin
  • Compatible with php 8.2 , 8.3 and 8.4

🛠 Usage

Lint Code

composer lint

Run Unit Test

composer test:unit

Static Analysis

composer test:types

Test Code Format

composer test:lint

Run Everything

composer test

🏗 Folder Structure

src/                # Main source code
tests/              # Unit and feature tests

✨ Example Implementation

Greeting Contract

<?php
declare(strict_types=1);

namespace RoyRakesh\SkeletonPhp\Contracts;

interface GreetingContract
{
    public function greet(string $name): string;
}

Greeting Service

<?php
declare(strict_types=1);

namespace RoyRakesh\SkeletonPhp\Services;

use RoyRakesh\SkeletonPhp\Contracts\GreetingContract;

class GreetingService implements GreetingContract
{
    public function greet(string $name): string
    {
        return "Hello, $name!";
    }
}

Greeting Class

<?php
declare(strict_types=1);

namespace RoyRakesh\SkeletonPhp;

use RoyRakesh\SkeletonPhp\Services\GreetingService;

final class Greeting
{
    private GreetingService $greetingService;

    public function __construct()
    {
        $this->greetingService = new GreetingService();
    }

    public function greet(string $name): string
    {
        return $this->greetingService->greet($name);
    }
}

Pest Test for GreetingService

<?php

declare(strict_types=1);

use RoyRakesh\SkeletonPhp\Services\GreetingService;

it('returns a greeting message', function () {
    $service = new GreetingService();

    expect($service->greet('Rakesh'))->toBe('Hello, Rakesh!');
});

Pest Test for Greeting

<?php

declare(strict_types=1);

use RoyRakesh\SkeletonPhp\Greeting;

it('greets a user with a name', function () {
    $greeting = new Greeting();

    $result = $greeting->greet('Rakesh');

    expect($result)->toBe('Hello, Rakesh!');
});

it('greets a user with an empty name', function () {
    $greeting = new Greeting();

    $result = $greeting->greet('');

    expect($result)->toBe('Hello, !'); 
});

🔗 Credits

This package utilizes the following open-source tools:

  • PestPHP - A modern PHP testing framework.
  • Laravel Pint - An opinionated PHP code formatter.
  • PHPStan - Static analysis tool for PHP.
  • Rector - Automated code refactoring tool.
  • @nunomaduro - Thanks for insping me to create opensource php projects.

📝 License

This project is licensed under the MIT License.

👤 Author

Rakesh Roy
Website | Email

About

A skeleton for modern PHP development, providing a clean structure and essential tooling.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages