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
38 changes: 38 additions & 0 deletions .github/workflows/code-standart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: DEPLOY AND BUILD

on: ['push', 'pull_request']

jobs:
coding-standard:
name: Coding Standard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none

- name: Get composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --no-suggest --prefer-dist --no-interaction

- name: Check coding style
run: composer cs-check

- name: Run tests
run: composer tests
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/composer.lock
/phpunit.xml
/vendor/
/.idea/
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM php:8.4-cli-alpine

WORKDIR /app

COPY . /app

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Skeleton PHP Docker
48 changes: 48 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "deniskorbakov/skeleton-php-docker",
"description": "A skeleton php libs with docker",
"keywords": ["php", "skeleton", "package", "docker"],
"type": "libarary",
"license": "MIT",
"authors": [
{
"name": "Denis Korbakov",
"email": "korbakovd@gmail.com"
}
],
"autoload": {
"psr-4": {
"DenisKorbakov\\SkeletonPhpDocker\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "stable",
"scripts": {
"tests": "php ./vendor/bin/pest",
"cs-check": [
"@phpstan",
"@cs",
"@rector"
],
"phpstan": "phpstan analyse --memory-limit=2G",
"rector": "rector",
"cs": "phpcs"
},
"require-dev": {
"pestphp/pest": "^3.8",
"phpstan/phpstan": "^2.1",
"rector/rector": "*",
"squizlabs/php_codesniffer": "^3.13",
"slevomat/coding-standard": "^8.20"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.7'
services:
app:
container_name: scribe-plugin
build:
context: ./
volumes:
- ./:/app
tty: true
stdin_open: true
26 changes: 26 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# command for init project
init: build install

# command for start app
up:
docker compose up -d

# command for build app
build:
docker compose up -d --build

# command for exec in container
exec:
docker exec -it scribe-plugin /bin/sh

# command for install pkg
install:
docker exec -i scribe-plugin composer install --dev

# command for run verify code
code-check:
docker exec -i scribe-plugin composer cs-check

# command for run tests
test:
docker exec -i scribe-plugin composer tests
76 changes: 76 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0"?>
<ruleset name="Coding standard">
<description>Coding standard</description>
<config name="installed_paths" value="../../slevomat/coding-standard"/>

<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>

<!-- inherit rules from: -->
<rule ref="PSR12"/>
<rule ref="PSR1.Files.SideEffects">
</rule>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="240"/>
<property name="absoluteLineLimit" value="320"/>
</properties>
</rule>

<!-- Ban some functions -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="is_null" value="null"/>
<element key="create_function" value="null"/>
</property>
</properties>
</rule>

<!-- Functional rules -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="linesCountBeforeDeclare" value="1"/>
<property name="linesCountAfterDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/>

<!-- Rules for detecting dead or useless code -->
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable"/>
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable"/>
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>

<!-- Rules for consistent code looks -->
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
</ruleset>
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: max
paths:
- src

reportUnmatchedIgnoredErrors: true
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>app</directory>
<directory>src</directory>
</include>
</source>
</phpunit>
77 changes: 77 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->rules([
AddVoidReturnTypeWhereNoReturnRector::class,
DeclareStrictTypesRector::class,
ClosureReturnTypeRector::class,
ReturnTypeFromStrictTypedCallRector::class,
ReturnTypeFromStrictNewArrayRector::class,
ReturnTypeFromReturnDirectArrayRector::class,
TypedPropertyFromStrictConstructorRector::class,
CompleteDynamicPropertiesRector::class,
InlineArrayReturnAssignRector::class,
ExplicitBoolCompareRector::class,
SwitchNegatedTernaryRector::class,
NewlineBeforeNewAssignSetRector::class,
EncapsedStringsToSprintfRector::class,
PostIncDecToPreIncDecRector::class,
SymplifyQuoteEscapeRector::class,
RemoveUnusedPromotedPropertyRector::class,
RemoveUnusedPrivateMethodRector::class,
RemoveUnusedPrivatePropertyRector::class,
ClassPropertyAssignToConstructorPromotionRector::class,
ReadOnlyPropertyRector::class,
PrivatizeFinalClassMethodRector::class,
PrivatizeFinalClassPropertyRector::class,
]);

$rectorConfig->skip([
CompactToVariablesRector::class,
RemoveEmptyClassMethodRector::class,
]);

$rectorConfig->sets([
SetList::CODE_QUALITY,
SetList::TYPE_DECLARATION,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
]);

$rectorConfig->phpVersion(PhpVersion::PHP_84);
};
13 changes: 13 additions & 0 deletions src/Example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace DenisKorbakov\SkeletonPhpDocker;

final class Example
{
public function foo(): string
{
return 'bar';
}
}
12 changes: 12 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
//
}
18 changes: 18 additions & 0 deletions tests/Unit/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Tests\Unit;

use DenisKorbakov\SkeletonPhpDocker\Example;
use Tests\TestCase;

uses(TestCase::class);

test('foo', function (): void {
$example = new Example();

$result = $example->foo();

expect($result)->toBe('bar');
});