Skip to content

Commit

Permalink
V2.0.0
Browse files Browse the repository at this point in the history
# Refactor Termii library to a more modular and maintainable
architecture

Refactor of the Termii PHP library by removing outdated files and
dependencies. introduced new resource structures, including Resources,
Endpoints, DTO for improved organization and functionality. The Termii
class has been updated to integrate these resources, offering a more
modular and maintainable architecture for interacting with Termii's API.

### Highlights of Changes in `v2`
#### **1. New Features**
- **Insight API Support**
Added new endpoints for the Insight API, including:
    - Balance retrieval.
    - Phone number status check.
    - DND (Do Not Disturb) checks.
    - Message history retrieval.
Accompanied by corresponding tests and resources for smoother usage.

- **Token API for OTP Workflows**
Implemented endpoints for generating, sending, and verifying OTPs across
multiple channels including:
    - SMS, voice, email, and in-app.
Enhanced with test cases and documentation updates.

- **Custom `RequestException` Class**
Introduced a new `TermiiRequestException` to replace Saloon's base
exceptions. This improves exception handling by centralizing and
streamlining error management.
- **Troubleshooting Support**
Added initial debugging and troubleshooting capabilities to help
developers resolve integration issues quickly.

#### **2. Codebase Refactoring and Optimization**
- Consolidated requests into **Endpoint Classes** for improved clarity
and maintainability, aligning with a more modular architecture.
- Refactored the `Termii` class to follow the **Singleton Pattern** for
managing `TermiiConnector` initialization, reducing redundancy and
improving resource handling.
- Introduced a new `ConvertsDtoToRequestArray` interface, implemented
across relevant DTOs for consistency in request array conversion.

#### **3. Coding Standards and Quality**
- Applied **PHP-CS-Fixer** for consistent code formatting and adherence
to modern standards.
- Introduced PHPStan configuration for static analysis, enhancing code
quality and reliability.

#### **4. Testing Improvements**
- Added tests for new APIs and refactored existing test cases,
especially around updated resources like `CampaignApiTest`.
- Integrated a GitHub Actions workflow for automated testing
(`ci(tests)`), ensuring better CI/CD coverage.

#### **5. Documentation Updates**
- Revised the README to include updated examples of using various APIs
(`Messaging`, `Campaigns`, `Phonebook`, `Contact Management`, etc.).
- Added instructions for new features and clarified the usage of updated
SDK functionalities.

### Breaking Changes
- Code restructuring (e.g., endpoint consolidations, new exceptions)
will impact downstream projects by requiring updates to match the latest
architecture.
  • Loading branch information
Douglasokolaa authored Dec 16, 2024
2 parents fc90044 + 9222c6c commit 5af64f4
Show file tree
Hide file tree
Showing 85 changed files with 8,259 additions and 1,979 deletions.
3 changes: 0 additions & 3 deletions .env.example

This file was deleted.

7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ensure all text files use LF line endings
* text eol=lf

# Specific file types
*.php text eol=lf
*.json text eol=lf
*.md text eol=lf
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [Douglasokolaa]
27 changes: 27 additions & 0 deletions .github/workflows/php-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: php-cs

on:
push:
paths:
- '**.php'
pull_request:
branches: [ "master", "develop" ]

jobs:
php-cs-lint:
name: analyze
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: none

- uses: actions/checkout@v4

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

- name: Lint
run: ./vendor/bin/php-cs-fixer check --allow-risky=yes
29 changes: 29 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PHPStan

on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'
- '.github/workflows/phpstan.yml'
pull_request:
branches: [ "master", "develop" ]

jobs:
phpstan:
name: analyze
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: none

- uses: actions/checkout@v4

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

- name: Run PHPStan
run: ./vendor/bin/phpstan analyze --error-format=github
36 changes: 36 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Tests

on:
push:
paths:
- '**.php'
- 'composer.json'
- 'composer.lock'
- 'phpunit.xml'
pull_request:
branches: [ "master", "develop" ]

jobs:
pest:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
php-versions: [ '8.2', '8.3', '8.4' ]
phpunit-versions: [ 'latest' ]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}

- uses: actions/checkout@v3
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: run tests
run: ./vendor/bin/pest
57 changes: 57 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

return (new Config())
->setRules([
'@PSR12' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'no_trailing_comma_in_singleline_array' => true,
'trim_array_spaces' => true,
'single_quote' => true,
'blank_line_after_namespace' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
'property' => 'one',
],
],
'function_declaration' => ['closure_function_spacing' => 'none'],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
],
'visibility_required' => ['elements' => ['property', 'method', 'const']],

'binary_operator_spaces' => ['default' => 'align_single_space_minimal'],
'cast_spaces' => ['space' => 'single'],
'concat_space' => ['spacing' => 'one'],

'control_structure_continuation_position' => ['position' => 'same_line'],
'curly_braces_position' => [
'control_structures_opening_brace' => 'same_line',
'functions_opening_brace' => 'next_line_unless_newline_at_signature_end',
'classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
],

'phpdoc_align' => ['align' => 'vertical'],
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'return_type_declaration' => ['space_before' => 'none'],
'declare_strict_types' => false,
'no_blank_lines_after_phpdoc' => true,
'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']],
'no_trailing_whitespace' => true,
'no_whitespace_in_blank_line' => true,
'semicolon_after_instruction' => true,
])
->setFinder($finder)
->setIndent(" ")
->setLineEnding("\n");
Loading

0 comments on commit 5af64f4

Please sign in to comment.