Skip to content

Commit

Permalink
Merge Development into Master (#1)
Browse files Browse the repository at this point in the history
* a Little thing 😅

* Applying PHP-CS-Fixer

* Update CI workflow + Adding new Release workflow to automate creating releases based on tags

* Add PHPStan config file

* Stop ignoring developer/machine specific folders

Using the global .gitignore instead for ignoring such files & folders

* Update README.md

* Raising PHP support baseline to 8.2

* Seems that `shivammathur/setup-php` does not support enabling imagick extension on windows platforms

* Small-Fix: Uppercasing directory name

* Replace Annotations with Attributes in Unit Tests

* Fix Style typo
  • Loading branch information
ahmedghanem00 authored May 8, 2024
1 parent fd570d0 commit 39b8c17
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 163 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
- push
- pull_request

jobs:
tests:
name: Tests

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os:
- ubuntu-latest

php-version:
- 8.2
- 8.3

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

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: imagick, gd
ini-values: memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On

- name: Install dependencies with Composer
run: composer install --prefer-dist --no-ansi --no-interaction --no-progress

- name: Run PHP-CS-Fixer in Linter Mode
run: composer run-script php-cs-fixer -- --dry-run --show-progress=dots --using-cache=no --verbose

- name: Run PHPStan
run: composer run-script phpstan

- name: Install Tesseract
run: sudo apt install tesseract-ocr

- name: Run test-suites
run: composer run-script test
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- "**"

jobs:
create-release:
name: Create Release

runs-on: ubuntu-latest

permissions:
contents: write

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

- name: Determine tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.RELEASE_TAG }}
name: Release v${{ env.RELEASE_TAG }}
48 changes: 0 additions & 48 deletions .github/workflows/testing.yml

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/.idea/
/examples/
/vendor/
/.phpunit.cache/
/composer.lock
/phpunit.xml
/.phpunit.result.cache
/.php-cs-fixer.cache
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

$header = <<<EOF
This file is part of the TesseractOCR package.
(c) Ahmed Ghanem <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->ignoreVCSIgnored(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true
])
->setUsingCache(true)
->setRiskyAllowed(true)
->setFinder($finder);
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tesseract-ocr
# Tesseract-OCR PHP Wrapper

A PHP wrapper for Tesseract-OCR binary.

Expand All @@ -23,7 +23,7 @@ Otherwise, You can do:

````php
$tesseract = new \ahmedghanem00\TesseractOCR\Tesseract("path/to/binary/location");
# OR
# OR, If you already have an initiated instance
$tesseract->setBinaryPath("path/to/binary/location");
````

Expand Down Expand Up @@ -63,8 +63,9 @@ To OCR an Image:

````php
$result = $tesseract->recognize("test.png");
##
## OR
$result = $tesseract->recognize("https://example.com/test.png");
## etc.
````

Thanks to the [Intervention/image](https://github.com/Intervention/image) package. The recognize method can accept
Expand Down Expand Up @@ -146,4 +147,4 @@ You can also run `tesseract --print-parameters` to see the list of available con

# Licence

tesseract-ocr is licensed under the [MIT License](http://opensource.org/licenses/MIT).
Package is licensed under the [MIT License](http://opensource.org/licenses/MIT). For more info, You can take a look at the [License File](LICENSE).
33 changes: 25 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,63 @@
"description": "A PHP wrapper for Tesseract-OCR binary",
"type": "library",
"license": "MIT",

"keywords": [
"tesseract",
"ocr",
"text recognition",
"ocr recognition",
"php-wrapper"
],

"authors": [
{
"name": "Ahmed Ghanem",
"email": "[email protected]",
"homepage": "https://github.com/ahmedghanem00"
}
],

"autoload": {
"psr-4": {
"ahmedghanem00\\TesseractOCR\\": "src/"
}
},

"autoload-dev": {
"psr-4": {
"ahmedghanem00\\TesseractOCR\\Tests\\": "tests/"
}
},

"require": {
"php": ">=8.1",
"ext-gd": "*",
"symfony/string": "6.*",
"symfony/process": "6.*",
"intervention/image": "2.7.*"
"php": "^8.2",
"symfony/string": "^6.0 || ^7.0",
"symfony/process": "^6.0 || ^7.0",
"intervention/image": "^2.7.0"
},

"require-dev": {
"ext-gd": "*",
"ext-imagick": "*",
"phpunit/phpunit": "dev-main",
"phpstan/phpstan": "1.10.x-dev",
"phpstan/extension-installer": "^1.3",
"friendsofphp/php-cs-fixer": "^3.54",
"smalot/pdfparser": "dev-master"
},

"scripts": {
"test": "@php vendor/bin/phpunit",
"phpstan": "@php vendor/bin/phpstan analyse src tests"
"test": "vendor/bin/phpunit",
"phpstan": "vendor/bin/phpstan analyse",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix"
},
"minimum-stability": "dev"

"minimum-stability": "stable",

"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
# Ignore this error temporary for now
message: "#^Method ahmedghanem00\\\\TesseractOCR\\\\Exception\\\\Execution\\\\UnsuccessfulExecutionException\\:\\:newFromProcess\\(\\) should return static\\(ahmedghanem00\\\\TesseractOCR\\\\Exception\\\\Execution\\\\UnsuccessfulExecutionException\\) but returns ahmedghanem00\\\\TesseractOCR\\\\Exception\\\\Execution\\\\UnsuccessfulExecutionException\\.$#"
count: 1
path: src/Exception/Execution/UnsuccessfulExecutionException.php
11 changes: 11 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5

paths:
- src/
- tests/

reportUnmatchedIgnoredErrors: true
32 changes: 11 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="unit">
<directory>tests/unit</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" executionOrder="depends,defects" requireCoverageMetadata="true" beStrictAboutCoverageMetadata="true" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
6 changes: 4 additions & 2 deletions src/ConfigBag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/*
* This file is part of the TesseractOCR package.
*
Expand All @@ -23,7 +25,7 @@ class ConfigBag
private array $parameters = [];

/**
* @return static
* @return self
*/
public static function new(): self
{
Expand Down
4 changes: 3 additions & 1 deletion src/Enum/OEM.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/*
* This file is part of the TesseractOCR package.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Enum/PSM.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/*
* This file is part of the TesseractOCR package.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/EmptyResultException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/*
* This file is part of the TesseractOCR package.
*
Expand Down
5 changes: 3 additions & 2 deletions src/Exception/Execution/InvalidConfigException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/*
* This file is part of the TesseractOCR package.
*
Expand All @@ -15,5 +17,4 @@
*/
class InvalidConfigException extends UnsuccessfulExecutionException
{

}
5 changes: 4 additions & 1 deletion src/Exception/Execution/UnsuccessfulExecutionException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/*
* This file is part of the TesseractOCR package.
*
Expand All @@ -12,6 +14,7 @@

use RuntimeException;
use Symfony\Component\Process\Process;

use function Symfony\Component\String\u;

/**
Expand Down
Loading

0 comments on commit 39b8c17

Please sign in to comment.