Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Jan 7, 2024
0 parents commit 7936e80
Show file tree
Hide file tree
Showing 21 changed files with 847 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
push:
schedule:
- cron: '0 0 * * *'

jobs:
php81:
name: PHP 8.1
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: composer test
uses: docker://chubbyphp/ci-php81:latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
php82:
name: PHP 8.2
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: composer test
uses: docker://chubbyphp/ci-php82:latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
php83:
name: PHP 8.3
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v3
- name: composer test
uses: docker://chubbyphp/ci-php83:latest
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
- name: sonarcloud.io
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.idea/
.phpunit.cache
.vscode/
build/
composer.lock
vendor/
24 changes: 24 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->files()
->name('*.php')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
;

/** @var array $config */
$config = require __DIR__ . '/vendor/chubbyphp/chubbyphp-dev-helper/phpcs.php';

// rules is buggy
unset($config['rules']['simplified_null_return']);

return (new PhpCsFixer\Config)
->setIndent($config['indent'])
->setLineEnding($config['lineEnding'])
->setRules($config['rules'])
->setRiskyAllowed($config['riskyAllowed'])
->setFinder($finder)
;
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Dominik Zogg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# chubbyphp-parsing

[![CI](https://github.com/chubbyphp/chubbyphp-parsing/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyphp/chubbyphp-parsing/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/chubbyphp/chubbyphp-parsing/badge.svg?branch=master)](https://coveralls.io/github/chubbyphp/chubbyphp-parsing?branch=master)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyphp%2Fchubbyphp-parsing%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/chubbyphp-parsing/master)
[![Latest Stable Version](https://poser.pugx.org/chubbyphp/chubbyphp-parsing/v/stable.png)](https://packagist.org/packages/chubbyphp/chubbyphp-parsing)
[![Total Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-parsing/downloads.png)](https://packagist.org/packages/chubbyphp/chubbyphp-parsing)
[![Monthly Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-parsing/d/monthly)](https://packagist.org/packages/chubbyphp/chubbyphp-parsing)

[![bugs](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=bugs)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![code_smells](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=code_smells)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![coverage](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=coverage)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![duplicated_lines_density](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![ncloc](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=ncloc)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![alert_status](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=alert_status)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![security_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=security_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![sqale_index](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=sqale_index)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)
[![vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-parsing&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-parsing)


## Description



## Requirements

* php: ^8.1

## Installation

Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-parsing][1].

```sh
composer require chubbyphp/chubbyphp-parsing "^1.0"
```

## Usage

## Copyright

2024 Dominik Zogg

[1]: https://packagist.org/packages/chubbyphp/chubbyphp-parsing
65 changes: 65 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "chubbyphp/chubbyphp-parsing",
"description": "Chubbyphp Parse",
"keywords": [
"chubbyphp"
],
"license": "MIT",
"authors": [
{
"name": "Dominik Zogg",
"email": "[email protected]"
}
],
"require": {
"php": "^8.1"
},
"require-dev": {
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-mock": "^1.7",
"infection/infection": "^0.27.8",
"php-coveralls/php-coveralls": "^2.7.0",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.10.45",
"phpunit/phpunit": "^10.4.2"
},
"autoload": {
"psr-4": {
"Chubbyphp\\Parsing\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Chubbyphp\\Tests\\Parsing\\": "tests/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"phpstan/extension-installer": true
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"scripts": {
"fix:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --cache-file=build/phpcs.cache",
"test": [
"@test:lint",
"@test:unit",
"@test:integration",
"@test:infection",
"@test:static-analysis",
"@test:cs"
],
"test:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=97 --verbose --coverage=build/phpunit",
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-result-file=build/phpunit/result.cache",
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
"test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=8 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
"test:unit": "vendor/bin/phpunit --testsuite=Unit --coverage-text --coverage-clover=build/phpunit/clover.xml --coverage-html=build/phpunit/coverage-html --coverage-xml=build/phpunit/coverage-xml --log-junit=build/phpunit/junit.xml --cache-result-file=build/phpunit/result.cache"
}
}
20 changes: 20 additions & 0 deletions infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"source": {
"directories": [
"src"
]
},
"timeout": 10,
"logs": {
"text": "build/phpinfection/infection.log",
"html": "build/phpinfection/infection.html",
"json": "build/phpinfection/infection.json",
"summary": "build/phpinfection/summary.log",
"stryker": {
"report": "master"
}
},
"mutators": {
"@default": true
}
}
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
17 changes: 17 additions & 0 deletions phpunit.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" backupGlobals="false" colors="true" executionOrder="random" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Integration">
<directory>./tests/Integration</directory>
</testsuite>
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
10 changes: 10 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sonar.organization=chubbyphp
sonar.projectKey=chubbyphp_chubbyphp-parsing
sonar.projectName=chubbyphp-parsing

sonar.sources=src
sonar.tests=tests
sonar.language=php
sonar.sourceEncoding=UTF-8
sonar.php.coverage.reportPaths=build/phpunit/clover.xml
sonar.php.tests.reportPath=build/phpunit/junit.xml
20 changes: 20 additions & 0 deletions src/ParseError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\Parsing;

final class ParseError extends \RuntimeException implements ParseErrorInterface
{
public function __construct(private string $data) {}

public function __toString(): string
{
return $this->getData();
}

public function getData(): array|string
{
return $this->data;
}
}
12 changes: 12 additions & 0 deletions src/ParseErrorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\Parsing;

interface ParseErrorInterface extends \Throwable
{
public function __toString(): string;

public function getData(): array|string;
}
44 changes: 44 additions & 0 deletions src/ParseErrors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\Parsing;

final class ParseErrors extends \RuntimeException implements ParseErrorInterface
{
/**
* @var array<int|string, ParseErrorInterface>
*/
private array $parseErrors;

/**
* @param array<ParseErrorInterface> $parseErrors
*/
public function __construct(array $parseErrors)
{
foreach ($parseErrors as $key => $parseError) {
if (!$parseError instanceof ParseErrorInterface) {
$type = \is_object($parseError) ? $parseError::class : \gettype($parseError);

throw new \InvalidArgumentException(sprintf('Argument #1 value of #%s ($parseErrors) must be of type ParseError, %s given', (string) $key, $type));
}
}

$this->parseErrors = $parseErrors;
}

public function __toString(): string
{
return json_encode($this->getData());
}

public function getData(): array|string
{
$data = [];
foreach ($this->parseErrors as $key => $parseError) {
$data[$key] = $parseError->getData();
}

return $data;
}
}
32 changes: 32 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\Parsing;

use Chubbyphp\Parsing\Schema\ArraySchema;
use Chubbyphp\Parsing\Schema\ObjectSchema;
use Chubbyphp\Parsing\Schema\SchemaInterface;
use Chubbyphp\Parsing\Schema\StringSchema;

final class Parser
{
public function array(SchemaInterface $itemSchema): ArraySchema
{
return new ArraySchema($itemSchema);
}

/**
* @param array<string, SchemaInterface> $objectSchema
* @param class-string $classname
*/
public function object(array $objectSchema, string $classname = \stdClass::class): ObjectSchema
{
return new ObjectSchema($objectSchema, $classname);
}

public function string(): StringSchema
{
return new StringSchema();
}
}
15 changes: 15 additions & 0 deletions src/Result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\Parsing;

final class Result
{
public bool $success;

public function __construct(public mixed $data, public null|ParseErrorInterface $error)
{
$this->success = null === $error;
}
}
Loading

0 comments on commit 7936e80

Please sign in to comment.