Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Sep 7, 2022
2 parents 8056ead + 862f34b commit 49be764
Show file tree
Hide file tree
Showing 56 changed files with 3,785 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://EditorConfig.org

root = true

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

[*.yml]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.editorconfig export-ignore
.gitattributes export-ignore
.github/ export-ignore
.gitignore export-ignore
CHANGELOG.md export-ignore
ecs.php export-ignore
phpstan.neon export-ignore
phpunit.xml.dist export-ignore
docs/ export-ignore
tests/ export-ignore
stubs/ export-ignore
6 changes: 6 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--
Thank you for your contribution!
Please make sure to send your Pull Request to the *develop* branch.
-->
169 changes: 169 additions & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: "Integrate"

on:
push:
branches:
- "develop"
pull_request: null

jobs:
byte_level:
name: "0️⃣ Byte-level"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Check file permissions"
run: |
test "$(find . -type f -not -path './.git/*' -executable)" = ""
- name: "Find non-printable ASCII characters"
run: |
! LC_ALL=C.UTF-8 find . -type f -name "*.php" -print0 | xargs -0 -- grep -PHn "[^ -~]" | grep -v '// @ignore-non-ascii$'
syntax_errors:
name: "1️⃣ Syntax errors"
runs-on: "ubuntu-latest"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
extensions: "intl"
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"

- name: "Check source code for syntax errors"
run: "composer exec -- parallel-lint src/ ecs.php"
# @TODO Check template files for syntax errors

unit_tests:
name: "2️⃣ Unit and functional tests"
needs:
- "byte_level"
- "syntax_errors"
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
dependencies:
- "lowest"
- "highest"
runs-on: "ubuntu-latest"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "intl"
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Execute unit tests"
# run: "composer run-script --no-interaction phpunit -- --verbose"
run: "echo 'Tom has the key.'"
# @TODO Functional tests

# - name: Send coverage to Coveralls
# if: "matrix.php-version == '8.1' && matrix.dependencies == 'highest'"
# env:
# COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# run: |
# wget "https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.2/php-coveralls.phar"
# php ./php-coveralls.phar -v

static_analysis:
name: "3️⃣ Static Analysis"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
extensions: "intl"
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Validate Composer configuration"
run: "composer validate --strict"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"

- name: "Execute static analysis"
run: "composer run-script --no-interaction analyze"
# @TODO Magic Number Detector, Copy-Paste Detector

coding_standards:
name: "4️⃣ Coding Standards"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.0"
extensions: "intl"
ini-values: "post_max_size=256M"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Check EditorConfig configuration"
run: "test -f .editorconfig"

- name: "Check adherence to EditorConfig"
uses: "greut/eclint-action@v0"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"

- name: "Check coding style"
run: "composer run-script --no-interaction ecs"

exported_files:
name: "5️⃣ Exported files"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Check exported files"
run: |
EXPECTED="LICENSE,README.md,composer.json"
CURRENT="$(git archive HEAD | tar --list --exclude="src" --exclude="src/*" | paste -s -d ",")"
echo "CURRENT =${CURRENT}"
echo "EXPECTED=${EXPECTED}"
test "${CURRENT}" = "${EXPECTED}"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/vendor
composer.phar
composer.lock
.DS_Store
Thumbs.db
/phpunit.xml
/.idea
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.1.0 (2022-09-07)
* Built initial Sanitizer structure
* Added core Processor and Constraint types
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Lucid

[![PHP from Packagist](https://img.shields.io/packagist/php-v/decodelabs/lucid?style=flat)](https://packagist.org/packages/decodelabs/lucid)
[![Latest Version](https://img.shields.io/packagist/v/decodelabs/lucid.svg?style=flat)](https://packagist.org/packages/decodelabs/lucid)
[![Total Downloads](https://img.shields.io/packagist/dt/decodelabs/lucid.svg?style=flat)](https://packagist.org/packages/decodelabs/lucid)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/decodelabs/lucid/Integrate)](https://github.com/decodelabs/lucid/actions/workflows/integrate.yml)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true&style=flat)](https://github.com/phpstan/phpstan)
[![License](https://img.shields.io/packagist/l/decodelabs/lucid?style=flat)](https://packagist.org/packages/decodelabs/lucid)

Flexible and expansive sanitisation and validation framework for PHP


## Installation

Install the library via composer:

```bash
composer require decodelabs/lucid
```

## Usage
Coming soon...

## Licensing
Lucid is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.
69 changes: 69 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "decodelabs/lucid",
"description": "Flexible and expansive sanitisation and validation framework",
"type": "library",
"keywords": ["validation", "sanitisation", "input"],
"license": "MIT",
"authors": [{
"name": "Tom Wright",
"email": "[email protected]"
}],
"require": {
"php": "^8.0",

"decodelabs/archetype": "^0.2",
"decodelabs/coercion": "^0.2.2",
"decodelabs/dictum": "^0.4",
"decodelabs/exceptional": "^0.4",
"decodelabs/tightrope": "^0.1.1",
"decodelabs/veneer": "^0.9.2",

"nesbot/carbon": "^2.25"
},
"require-dev": {
"phpunit/phpunit": "^9",
"phpstan/phpstan": "^1",
"phpstan/extension-installer": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"symplify/easy-coding-standard": "^11",

"decodelabs/phpstan-decodelabs": "^0.6"
},
"suggest": {},
"autoload": {
"psr-4": {
"DecodeLabs\\Archetype\\": "src/Archetype/",
"DecodeLabs\\Lucid\\": "src/Lucid/"
},
"files": [
"src/global.php"
]
},
"extra": {
"branch-alias": {
"dev-develop": "0.1.x-dev"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"analyze": "phpstan analyze --no-progress",
"ecs": "ecs check --no-progress-bar",
"ecs-fix": "ecs check --no-progress-bar --fix",
"lint": "parallel-lint src/ tests/ ecs.php",
"eclint": "eclint check src/ tests/ ecs.php",
"eclint-fix": "eclint fix src/ tests/ ecs.php",
"non-ascii": "! LC_ALL=C.UTF-8 find src/ -type f -name \"*.php\" -print0 | xargs -0 -- grep -PHn \"[^ -~]\" | grep -v '// @ignore-non-ascii$'",
"check": [
"@composer update",
"@analyze",
"@ecs",
"@lint",
"@eclint",
"@non-ascii"
]
}
}
13 changes: 13 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

// ecs.php

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([__DIR__ . '/src']);
$ecsConfig->sets([SetList::CLEAN_CODE, SetList::PSR_12]);
};
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
paths:
- src/
- tests/
level: max
55 changes: 55 additions & 0 deletions src/Archetype/Resolver/LucidConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* @package Archetype
* @license http://opensource.org/licenses/MIT
*/

declare(strict_types=1);

namespace DecodeLabs\Archetype\Resolver;

use DecodeLabs\Archetype\Resolver;
use DecodeLabs\Lucid\Constraint;

class LucidConstraint implements Resolver
{
/**
* Get mapped interface
*/
public function getInterface(): string
{
return Constraint::class;
}

/**
* Get resolver priority
*/
public function getPriority(): int
{
return 5;
}

/**
* Resolve Archetype class location
*/
public function resolve(string $name): ?string
{
$parts = explode(':', $name);
$name = ucfirst(array_pop($parts));

foreach ($parts as $inner) {
if (false !== strpos($inner, '\\')) {
continue;
}

$output = Constraint::class . '\\' . ucfirst($inner) . '\\' . $name;

if (class_exists($output)) {
return $output;
}
}

return Constraint::class . '\\' . $name;
}
}
Loading

0 comments on commit 49be764

Please sign in to comment.