Skip to content

Commit

Permalink
Add various new cell validation rules (#103)
Browse files Browse the repository at this point in the history
A number of new cell validation rules have been added to both the JSON
and PHP schema files, including checks for prime numbers, Fibonacci
numbers, even and odd numbers, Roman numerals, and phone numbers among
others. The validation logic for these new rules has also been added.
  • Loading branch information
SmetDenis committed Mar 27, 2024
1 parent aa6e8e5 commit 246f2c5
Show file tree
Hide file tree
Showing 38 changed files with 1,820 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
name: Demo

on:
release:
types: [ created ]
workflow_run:
workflows: [ "Publish Docker" ]
types:
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ jobs:
tools: composer
extensions: ast

- name: Build project
- name: Install project
run: make build --no-print-directory

## To see the difference between the current and the lowest versions
- name: Downgrade dependencies
run: make update --no-print-directory

- name: 🧪 PHPUnit Tests
Expand Down Expand Up @@ -143,7 +147,11 @@ jobs:
tools: composer
extensions: ast

- name: Build project
- name: Install project
run: make build --no-print-directory

## To see the difference between the current and the latest versions
- name: Upgrade dependencies
run: make update --no-print-directory

- name: 🧪 PHPUnit Tests
Expand Down Expand Up @@ -277,6 +285,7 @@ jobs:
context: .
push: true
tags: jbzoo/csv-blueprint:master
platforms: linux/amd64,linux/arm64/v8,linux/386


verify-ga:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ INVALID_SCHEMA ?= --schema='./tests/schemas/demo_invalid.yml'

# Build/install ########################################################################################################
build: ##@Project Build project in development mode
@composer install --optimize-autoloader
@composer install --optimize-autoloader --ansi
@rm -f `pwd`/ci-report-converter
@make build-version

Expand All @@ -56,7 +56,7 @@ build-version: ##@Project Save version info

update: ##@Project Update dependencies
@echo "Composer flags: $(JBZOO_COMPOSER_UPDATE_FLAGS)"
@composer update $(JBZOO_COMPOSER_UPDATE_FLAGS)
@composer update $(JBZOO_COMPOSER_UPDATE_FLAGS) --ansi


# Demo #################################################################################################################
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![GitHub Release](https://img.shields.io/github/v/release/jbzoo/csv-blueprint?label=Latest)](https://github.com/jbzoo/csv-blueprint/releases) [![Total Downloads](https://poser.pugx.org/jbzoo/csv-blueprint/downloads)](https://packagist.org/packages/jbzoo/csv-blueprint/stats) [![Docker Pulls](https://img.shields.io/docker/pulls/jbzoo/csv-blueprint.svg)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags) [![Docker Image Size](https://img.shields.io/docker/image-size/jbzoo/csv-blueprint)](https://hub.docker.com/r/jbzoo/csv-blueprint/tags)

<!-- rules-counter -->
[![Static Badge](https://img.shields.io/badge/Rules-292-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml) [![Static Badge](https://img.shields.io/badge/Rules-81-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell) [![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray)](src/Rules/Aggregate) [![Static Badge](https://img.shields.io/badge/Rules-5-green?label=Extra%20checks&labelColor=blue&color=gray)](#extra-checks) [![Static Badge](https://img.shields.io/badge/Rules-142/54/8-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
[![Static Badge](https://img.shields.io/badge/Rules-304-green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray)](schema-examples/full.yml) [![Static Badge](https://img.shields.io/badge/Rules-93-green?label=Cell%20rules&labelColor=blue&color=gray)](src/Rules/Cell) [![Static Badge](https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray)](src/Rules/Aggregate) [![Static Badge](https://img.shields.io/badge/Rules-5-green?label=Extra%20checks&labelColor=blue&color=gray)](#extra-checks) [![Static Badge](https://img.shields.io/badge/Rules-119/54/8-green?label=Plan%20to%20add&labelColor=gray&color=gray)](tests/schemas/todo.yml)
<!-- /rules-counter -->

## Introduction
Expand Down Expand Up @@ -282,9 +282,28 @@ columns:
# See: https://en.wikipedia.org/wiki/ISO_639.
is_language_code: alpha-2 # Examples: "en", "eng"

# Filesystem (with IO!)
is_file_exists: true # Check if file exists on the filesystem (It's FS IO operation!).
is_dir_exists: true # Check if directory exists on the filesystem (It's FS IO operation!).

# Mathematical
is_fibonacci: true # Validates whether the input follows the Fibonacci integer sequence. Example: "8", "13".
is_prime_number: true # Validates a prime number. Example: "3", "5", "7", "11".
is_even: true # Check if the value is an even number. Example: "2", "4", "6".
is_odd: true # Check if the value is an odd number. Example: "1", "7", "11".
is_roman: true # Validates if the input is a Roman numeral. Example: "I", "IV", "XX".

# Identifications
phone: ALL # Validates if the input is a phone number. Specify the country code to validate the phone number for a specific country. Example: "ALL", "US", "BR".".

# Misc
is_version: true # Validates the string as version numbers using Semantic Versioning. Example: "1.2.3".
is_punct: true # Validates whether the input composed by only punctuation characters. Example: "!@#$%^&*()".
is_vowel: true # Validates whether the input contains only vowels. Example: "aei".
is_consonant: true # Validates if the input contains only consonants. Example: "bcd".
is_alnum: true # Validates whether the input is only alphanumeric. Example: "aBc123".
is_alpha: true # This is similar to `is_alnum`, but it does not allow numbers. Example: "aBc".

####################################################################################################################
# Data validation for the entire(!) column using different data aggregation methods.
# Depending on the file size and the chosen aggregation method - this can use a lot of RAM time.
Expand Down
27 changes: 15 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@
"prefer-stable" : true,

"require" : {
"php" : "^8.1",
"ext-mbstring" : "*",
"php" : "^8.1",
"ext-mbstring" : "*",

"league/csv" : "^9.15.0",
"jbzoo/data" : "^7.1.1",
"jbzoo/cli" : "^7.1.8",
"jbzoo/utils" : "^7.2.0",
"jbzoo/ci-report-converter" : "^7.2.1",
"league/csv" : "^9.15.0",
"jbzoo/data" : "^7.1.1",
"jbzoo/cli" : "^7.1.8",
"jbzoo/utils" : "^7.2.0",
"jbzoo/ci-report-converter" : "^7.2.1",

"symfony/yaml" : ">=6.4.3",
"symfony/filesystem" : ">=6.4.3",
"symfony/finder" : ">=6.4.0",
"markrogoyski/math-php" : "^2.9.0",
"respect/validation" : "^2.3.5"
"symfony/yaml" : ">=6.4.3",
"symfony/filesystem" : ">=6.4.3",
"symfony/finder" : ">=6.4.0",
"markrogoyski/math-php" : "^2.9.0",
"respect/validation" : "^2.3.6",
"giggsey/libphonenumber-for-php-lite" : "^8.13.33",
"giggsey/locale" : "^2.5",
"symfony/polyfill-mbstring" : "^1.29.0"
},

"require-dev" : {
Expand Down
148 changes: 142 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
<directory name="src/Rules"/>
</errorLevel>
</InvalidClassConstantType>
<TooManyArguments>
<errorLevel type="suppress">
<file name="src/Rules/Cell/Phone.php"/>
</errorLevel>
</TooManyArguments>
</issueHandlers>
</psalm>
19 changes: 18 additions & 1 deletion schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,25 @@

"is_country_code" : "alpha-2",
"is_language_code" : "alpha-2",

"is_file_exists" : true,
"is_dir_exists" : true
"is_dir_exists" : true,

"is_dir_exists" : true,
"is_fibonacci" : true,
"is_prime_number" : true,
"is_even" : true,
"is_odd" : true,
"is_roman" : true,

"phone" : "ALL",

"is_version" : true,
"is_punct" : true,
"is_vowel" : true,
"is_consonant" : true,
"is_alnum" : true,
"is_alpha" : true
},
"aggregate_rules" : {
"is_unique" : true,
Expand Down
15 changes: 15 additions & 0 deletions schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@

'is_file_exists' => true,
'is_dir_exists' => true,

'is_fibonacci' => true,
'is_prime_number' => true,
'is_even' => true,
'is_odd' => true,
'is_roman' => true,

'phone' => 'ALL',

'is_version' => true,
'is_punct' => true,
'is_vowel' => true,
'is_consonant' => true,
'is_alnum' => true,
'is_alpha' => true,
],

'aggregate_rules' => [
Expand Down

0 comments on commit 246f2c5

Please sign in to comment.