Skip to content

Commit f72a407

Browse files
committed
* Added static analysis & fixed all issues
* Updated phpunit * Fixed namespacing/autoloading of test suite * Added gitattributes to be more distribution friendly * Removed composer.lock from version control * Improved example RTF file generator * Updated class comments * Added Github actions
1 parent a89ab26 commit f72a407

28 files changed

Lines changed: 704 additions & 2087 deletions

.cs.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
5+
return (new Config())
6+
->setUsingCache(false)
7+
->setRiskyAllowed(true)
8+
->setRules(
9+
[
10+
'@PSR1' => true,
11+
'@PSR2' => true,
12+
'@Symfony' => true,
13+
'psr_autoloading' => true,
14+
// custom rules
15+
'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], // psr-5
16+
'phpdoc_to_comment' => false,
17+
'no_superfluous_phpdoc_tags' => false,
18+
'array_indentation' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'cast_spaces' => ['space' => 'none'],
21+
'concat_space' => ['spacing' => 'one'],
22+
'compact_nullable_type_declaration' => true,
23+
'declare_strict_types' => true,
24+
'declare_equal_normalize' => ['space' => 'none'],
25+
'general_phpdoc_annotation_remove' => [
26+
'annotations' => [
27+
'author',
28+
'package',
29+
],
30+
],
31+
'increment_style' => ['style' => 'post'],
32+
'list_syntax' => ['syntax' => 'short'],
33+
'echo_tag_syntax' => ['format' => 'long'],
34+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
35+
'phpdoc_align' => false,
36+
'phpdoc_no_empty_return' => false,
37+
'phpdoc_order' => true, // psr-5
38+
'phpdoc_no_useless_inheritdoc' => false,
39+
'protected_to_private' => false,
40+
'yoda_style' => false,
41+
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
42+
'ordered_imports' => [
43+
'sort_algorithm' => 'alpha',
44+
'imports_order' => ['class', 'const', 'function'],
45+
],
46+
'single_line_throw' => false,
47+
'blank_line_between_import_groups' => true,
48+
'fully_qualified_strict_types' => true,
49+
'no_null_property_initialization' => false,
50+
'nullable_type_declaration_for_default_null_value' => false,
51+
'operator_linebreak' => [
52+
'only_booleans' => true,
53+
'position' => 'beginning',
54+
],
55+
'global_namespace_import' => [
56+
'import_classes' => true,
57+
'import_constants' => null,
58+
'import_functions' => null
59+
],
60+
'class_definition' => [
61+
'space_before_parenthesis' => true,
62+
],
63+
'no_unused_imports' => true,
64+
]
65+
)
66+
->setFinder(
67+
PhpCsFixer\Finder::create()
68+
->in(__DIR__ . '/src')
69+
->in(__DIR__ . '/tests')
70+
->exclude(__DIR__ . '/vendor')
71+
->name('*.php')
72+
->ignoreDotFiles(true)
73+
->ignoreVCS(true)
74+
);

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.yml]
12+
indent_size = 2

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto eol=lf
2+
3+
/.github export-ignore
4+
/tests export-ignore
5+
/.cs.php export-ignore
6+
/.editorconfig export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/CONTRIBUTING.md export-ignore
10+
/phpcs.xml export-ignore
11+
/phpstan.neon export-ignore
12+
/phpunit.v9.xml export-ignore
13+
/phpunit.xml export-ignore

.github/workflows/tests.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: QA & Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
analysis-and-tests:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6' ]
18+
dependencies: [ stable ]
19+
include:
20+
- php-version: '7.4'
21+
dependencies: lowest
22+
- php-version: '8.0'
23+
dependencies: lowest
24+
- php-version: '8.1'
25+
dependencies: lowest
26+
- php-version: '8.2'
27+
dependencies: lowest
28+
- php-version: '8.3'
29+
dependencies: lowest
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php-version }}
39+
coverage: ${{ (matrix.php-version == '8.5' && matrix.dependencies == 'stable') && 'pcov' || 'none' }}
40+
tools: composer:v2
41+
continue-on-error: ${{ matrix.php-version == '8.6' }}
42+
43+
- name: Get Composer Cache Directory
44+
id: composer-cache
45+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
46+
47+
- name: Cache Composer dependencies
48+
uses: actions/cache@v4
49+
with:
50+
path: ${{ steps.composer-cache.outputs.dir }}
51+
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
52+
restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-
53+
54+
- name: Install Dependencies
55+
run: |
56+
if [ "${{ matrix.dependencies }}" = "lowest" ]; then
57+
composer update --prefer-lowest --prefer-dist --no-progress --no-interaction --ansi
58+
else
59+
composer update --prefer-dist --no-progress --no-interaction --ansi
60+
fi
61+
continue-on-error: ${{ matrix.php-version == '8.6' }}
62+
63+
- name: Run All Quality Assurance & Tests
64+
run: |
65+
if [ "${{ matrix.php-version }}" = "7.4" ] || [ "${{ matrix.dependencies }}" = "lowest" ]; then
66+
phpunit --configuration phpunit.v9.xml --colors=always
67+
else
68+
composer test:all
69+
fi
70+
continue-on-error: ${{ matrix.php-version == '8.6' }}
71+
72+
- name: Upload Coverage to Coveralls
73+
if: matrix.php-version == '8.5' && matrix.dependencies == 'stable'
74+
uses: coverallsapp/github-action@v2
75+
with:
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
file: build/logs/clover.xml

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
vendor/
1+
vendor/
2+
composer.lock
3+
coverage-report/

CHANGELOG.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
# PHP UTF8 To RTF
1+
# PHP UTF-8 To RTF
22
## Changelog
33
___________________________________
44
___________________________________
55
### v1.0.0
6-
* Initial release adding core functionality to locate & convert UTF8 characters
7-
___________________
6+
* Initial release adding core functionality to locate & convert UTF8 characters
7+
___________________
8+
### v1.0.1
9+
* Added static analysis & fixed all issues
10+
* Updated phpunit
11+
* Fixed namespacing/autoloading of test suite
12+
* Added gitattributes to be more distribution friendly
13+
* Removed composer.lock from version control
14+
* Improved example RTF file generator
15+
* Updated class comments
16+
* Added Github actions
17+
___________________

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# PHP UTF8 To RTF
2+
3+
[![QA & Tests](https://github.com/TomWilford/php-utf8-to-rtf/actions/workflows/tests.yml/badge.svg)](https://github.com/TomWilford/php-utf8-to-rtf/actions/workflows/tests.yml)
4+
[![Coverage Status](https://coveralls.io/repos/github/TomWilford/php-utf8-to-rtf/badge.svg?branch=main)](https://coveralls.io/github/TomWilford/php-utf8-to-rtf?branch=main)
5+
[![PHP Version](https://img.shields.io/badge/php-%5E7.4%20%7C%7C%20%5E8.0-8892bf.svg)](https://packagist.org/packages/TomWilford/php-utf8-to-rtf)
6+
[![License](https://img.shields.io/github/license/TomWilford/php-utf8-to-rtf)](LICENSE)
7+
28
## Description
39
A simple PHP class for converting UTF8 characters to an RTF safe version in a string.
410

511
## Installation
612
`composer require tomwilford/php-utf8-to-rtf`
7-
13+
814
## Usage
9-
> Requires PHP 7.0 or higher
15+
> Requires PHP 7.4 or higher
1016
1117
Instantiate the converter using:
1218

@@ -32,24 +38,24 @@ You can also convert an array of UTF8 strings:
3238
$convertedArray = $converter->convertArrayToRtf($arrayOfStrings);
3339
```
3440

35-
Finally, if you need to do any additional processing on the UTF8 characters before converting,
41+
Finally, if you need to do any additional processing on the UTF8 characters before converting,
3642
you can extract them as an array using:
3743
```php
3844
$arrayToConvert = $converter->locateCharactersInString($string);
3945
```
4046

4147
## Testing
4248
PHPUnit tests have been written using series of pangrams sourced online to try to best capture
43-
as many characters as possible in different languages being used in a natural way. Please see the
44-
[Pangrams trait](tests/Resources/Pangrams.php) for the pangram sources' credits.
49+
as many characters as possible in different languages being used in a natural way. Please see the
50+
[Pangrams trait](tests/Trait/Pangrams.php) for the pangram sources' credits.
4551

46-
There also is a short script that can [generate a test RTF file](tests/GenerateTestFile/generateTestFile.php) that
52+
There also is a short script that can [generate a test RTF file](tests/scripts/generate-test-rtf.php) that
4753
can be opened in a word processor to verify the results.
4854

4955
## Contributing
5056
Contributions are welcome, please see [CONTRIBUTING](CONTRIBUTING.md) for more information.
5157

52-
## Software License
58+
## Software License
5359
Copyright (c) 2022. Tom Wilford <hello@jollyblueman.com>
5460
All rights reserved.
5561

composer.json

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
"name": "tomwilford/php-utf8-to-rtf",
33
"description": "A simple package to convert UTF8 characters to RTF",
4-
"keywords": [],
5-
"homepage": "https://jollyblueman.com",
4+
"keywords": ["utf8", "rtf", "convert", "converter"],
65
"license": "BSD-3-Clause",
76
"authors": [
87
{
98
"name": "Tom Wilford",
10-
"homepage": "https://jollyblueman.com",
11-
"role": "Developer"
9+
"homepage": "https://jollyblueman.com"
1210
}
1311
],
1412
"support": {
@@ -19,8 +17,41 @@
1917
"Wilf\\PhpUtf8ToRtf\\": "src/"
2018
}
2119
},
20+
"autoload-dev": {
21+
"psr-4": {
22+
"Wilf\\PhpUtf8ToRtf\\Tests\\": "tests/TestCase",
23+
"Wilf\\PhpUtf8ToRtf\\Tests\\TestTrait\\": "tests/Trait/"
24+
}
25+
},
26+
"require": {
27+
"php": "^7.4 || ^8.0",
28+
"ext-mbstring": "*"
29+
},
2230
"require-dev": {
23-
"phpunit/phpunit": "^9.5",
31+
"friendsofphp/php-cs-fixer": "^3",
32+
"phpstan/phpstan": "^2",
33+
"phpunit/phpunit": "^9.6 || ^13",
2434
"squizlabs/php_codesniffer": "*"
35+
},
36+
"config": {
37+
"sort-packages": true,
38+
"process-timeout": 0
39+
},
40+
"scripts": {
41+
"cs:check": "php-cs-fixer fix --dry-run --format=txt --verbose --config=.cs.php --ansi",
42+
"cs:fix": "php-cs-fixer fix --config=.cs.php --ansi --verbose",
43+
"sniffer:check": "phpcs --standard=phpcs.xml",
44+
"sniffer:fix": "phpcbf --standard=phpcs.xml",
45+
"stan": "phpstan analyse -c phpstan.neon --no-progress --ansi",
46+
"test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --no-coverage",
47+
"test:coverage": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-text",
48+
"test:report": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-html coverage-report",
49+
"test:coverage-shield": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-clover build/logs/clover.xml",
50+
"test:all": [
51+
"@cs:check",
52+
"@stan",
53+
"@test",
54+
"@sniffer:check"
55+
]
2556
}
2657
}

0 commit comments

Comments
 (0)