Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Jan 13, 2025
0 parents commit 4668680
Show file tree
Hide file tree
Showing 34 changed files with 1,795 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml,*.yaml,*.neon]
indent_style = space
indent_size = 2
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto

/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
/ecs.php export-ignore
/tests export-ignore
/phpstan.neon export-ignore
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
labels:
- "dependencies"
- "composer"
versioning-strategy: "widen"
open-pull-requests-limit: 5

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
labels:
- "dependencies"
- "github-actions"
41 changes: 41 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests

on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.4]
stability: [prefer-lowest, prefer-stable]

name: PHP${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/pest --colors=always
47 changes: 47 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Static Analysis

on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
phpstan:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- 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 --prefer-dist --no-interaction --no-progress

- name: Cache phpstan results
uses: actions/cache@v4
with:
path: .phpstan-cache
key: "result-cache-${{ github.run_id }}" # always write a new cache
restore-keys: |
result-cache-
- name: Run phpstan
run: vendor/bin/phpstan analyse -c phpstan.dist.neon --no-progress --error-format=github
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vendor
composer.lock
.vscode
.env
.DS_Store
.phpstan-cache
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# json-schema

A PHP library for fluently building and validating JSON Schemas.

## Installation

```bash
composer require cortex/json-schema
```

## Usage

```php
$schema = ObjectSchema::make('user')
->description('User schema')
->properties(
StringSchema::make('name'),
StringSchema::make('email'),
);

$schema->toArray();
```

```json
{
"type": "object",
"title": "user",
"description": "User schema",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
```
62 changes: 62 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "cortexphp/json-schema",
"description": "A fluent JSON Schema builder for PHP",
"keywords": [
"json",
"schema",
"cortex"
],
"homepage": "https://github.com/cortexphp/json-schema",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Sean Tymon",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^8.3",
"opis/json-schema": "^2.3"
},
"require-dev": {
"pestphp/pest": "^3.0",
"phpstan/phpstan": "^2.0",
"rector/rector": "^2.0",
"symplify/easy-coding-standard": "^12.5"
},
"autoload": {
"psr-4": {
"Cortex\\JsonSchema\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Cortex\\JsonSchema\\Tests\\": "tests/"
}
},
"scripts": {
"test": "pest",
"ecs": "ecs check --fix",
"rector": "rector process",
"stan": "phpstan analyse",
"format": [
"@rector",
"@ecs"
],
"check": [
"@format",
"@test",
"@stan"
]
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
94 changes: 94 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
use PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBetweenImportGroupsFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use Symplify\CodingStandard\Fixer\Annotation\RemovePHPStormAnnotationFixer;
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff;

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withRootFiles()
->withSpacing(indentation: Option::INDENTATION_SPACES)
->withPreparedSets(
psr12: true,
common: true,
cleanCode: true,
strict: true,
)
->withPhpCsFixerSets(
php83Migration: true,
)
->withRules([
NotOperatorWithSuccessorSpaceFixer::class,
RemovePHPStormAnnotationFixer::class,
SingleLineCommentSpacingFixer::class,
NoTrailingWhitespaceInCommentFixer::class,
BlankLineBetweenImportGroupsFixer::class,
SingleLineEmptyBodyFixer::class,
])
->withConfiguredRule(FunctionDeclarationFixer::class, [
'closure_fn_spacing' => FunctionDeclarationFixer::SPACING_NONE,
])
->withConfiguredRule(TrailingCommaInMultilineFixer::class, [
'after_heredoc' => true,
'elements' => [
TrailingCommaInMultilineFixer::ELEMENTS_ARGUMENTS,
TrailingCommaInMultilineFixer::ELEMENTS_ARRAYS,
TrailingCommaInMultilineFixer::ELEMENTS_PARAMETERS,
],
])
->withConfiguredRule(OrderedImportsFixer::class, [
'sort_algorithm' => OrderedImportsFixer::SORT_LENGTH,
'imports_order' => [
OrderedImportsFixer::IMPORT_TYPE_CLASS,
OrderedImportsFixer::IMPORT_TYPE_FUNCTION,
OrderedImportsFixer::IMPORT_TYPE_CONST,
],
])
->withConfiguredRule(ClassAttributesSeparationFixer::class, [
'elements' => [
'property' => ClassAttributesSeparationFixer::SPACING_ONE,
'method' => ClassAttributesSeparationFixer::SPACING_ONE,
'trait_import' => ClassAttributesSeparationFixer::SPACING_NONE,
],
])
->withConfiguredRule(ClassDefinitionFixer::class, [
'inline_constructor_arguments' => false,
'space_before_parenthesis' => true,
])
->withConfiguredRule(PhpdocSeparationFixer::class, [
'groups' => [
['deprecated', 'link', 'see', 'since'],
['author', 'copyright', 'license'],
['category', 'package', 'subpackage'],
['property', 'property-read', 'property-write'],
['param'],
['throws'],
['return'],
],
])
->withConfiguredRule(BlankLineBeforeStatementFixer::class, [
'statements' => ['return', 'throw', 'if', 'switch', 'do', 'yield', 'try'],
])
->withSkip([
OrderedClassElementsFixer::class,
AssignmentInConditionSniff::class,
]);
5 changes: 5 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 8
paths:
- src
tmpDir: .phpstan-cache
17 changes: 17 additions & 0 deletions phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
Loading

0 comments on commit 4668680

Please sign in to comment.