-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 32309b3
Showing
12 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
schedule: | ||
- cron: '0 0 * * *' | ||
jobs: | ||
tests: | ||
name: tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-version: ['8.1', '8.2', '8.3', '8.4'] | ||
steps: | ||
- name: Setup php ${{ matrix.php-version }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Validate composer.json | ||
run: composer validate | ||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress | ||
- name: Run test suites | ||
run: | | ||
mkdir --parents build/logs | ||
vendor/bin/phpunit --coverage-clover=build/logs/clover.xml | ||
- name: Upload coverage results | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
composer global require php-coveralls/php-coveralls | ||
php-coveralls --coverage_clover=build/logs/clover.xml -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor | ||
.phpunit.result.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 shimomo | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Boatrace Sakura Trimmer | ||
|
||
[![Build Status](https://github.com/boatrace-sakura/trimmer/workflows/tests/badge.svg)](https://github.com/boatrace-sakura/trimmer/actions?query=workflow%3Atests) | ||
[![Coverage Status](https://coveralls.io/repos/github/boatrace-sakura/trimmer/badge.svg?branch=main)](https://coveralls.io/github/boatrace-sakura/trimmer?branch=main) | ||
[![Latest Stable Version](https://poser.pugx.org/boatrace-sakura/trimmer/v/stable)](https://packagist.org/packages/boatrace-sakura/trimmer) | ||
[![Latest Unstable Version](https://poser.pugx.org/boatrace-sakura/trimmer/v/unstable)](https://packagist.org/packages/boatrace-sakura/trimmer) | ||
[![License](https://poser.pugx.org/boatrace-sakura/trimmer/license)](https://packagist.org/packages/boatrace-sakura/trimmer) | ||
|
||
## Installation | ||
```bash | ||
composer require boatrace-sakura/trimmer | ||
``` | ||
|
||
## Usage | ||
```php | ||
<?php | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
use Boatrace\Sakura\Trimmer; | ||
|
||
var_dump(Trimmer::trim(null)); // NULL | ||
var_dump(Trimmer::trim(' 競艇 ')); // string(6) "競艇" | ||
|
||
var_dump(Trimmer::ltrim(null)); // NULL | ||
var_dump(Trimmer::ltrim(' 競艇 ')); // string(7) "競艇 " | ||
|
||
var_dump(Trimmer::rtrim(null)); // NULL | ||
var_dump(Trimmer::rtrim(' 競艇 ')); // string(7) " 競艇" | ||
``` | ||
|
||
## License | ||
The Boatrace Sakura Trimmer is open source software licensed under the [MIT license](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "boatrace-sakura/trimmer", | ||
"description": "The Boatrace Sakura Trimmer.", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "shimomo", | ||
"email": "developer@shimomo.net" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"php-di/php-di": "^6.0 || ^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Boatrace\\Sakura\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Boatrace\\Sakura\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return [ | ||
'Trimmer' => \DI\create('\Boatrace\Sakura\Trimmer')->constructor( | ||
\DI\get('MainTrimmer') | ||
), | ||
'MainTrimmer' => function ($container) { | ||
return $container->get('\Boatrace\Sakura\MainTrimmer'); | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
|
||
<testsuites> | ||
<testsuite name="boatrace-sakura"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Boatrace\Sakura; | ||
|
||
/** | ||
* @author shimomo | ||
*/ | ||
class MainTrimmer | ||
{ | ||
/** | ||
* @param string|null $value | ||
* @param string $characters | ||
* @return string|null | ||
*/ | ||
public function trim(?string $value, string $characters = "\x00\x09\x0A\x0B\x0D\x20"): ?string | ||
{ | ||
return is_null($value) ? null : trim($value, $characters); | ||
} | ||
|
||
/** | ||
* @param string|null $value | ||
* @param string $characters | ||
* @return string|null | ||
*/ | ||
public function ltrim(?string $value, string $characters = "\x00\x09\x0A\x0B\x0D\x20"): ?string | ||
{ | ||
return is_null($value) ? null : ltrim($value, $characters); | ||
} | ||
|
||
/** | ||
* @param string|null $value | ||
* @param string $characters | ||
* @return string|null | ||
*/ | ||
public function rtrim(?string $value, string $characters = "\x00\x09\x0A\x0B\x0D\x20"): ?string | ||
{ | ||
return is_null($value) ? null : rtrim($value, $characters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Boatrace\Sakura; | ||
|
||
use DI\Container; | ||
use DI\ContainerBuilder; | ||
|
||
/** | ||
* @author shimomo | ||
*/ | ||
class Trimmer | ||
{ | ||
/** | ||
* @var \Boatrace\Sakura\Trimmer | ||
*/ | ||
protected static Trimmer $instance; | ||
|
||
/** | ||
* @var \DI\Container | ||
*/ | ||
protected static Container $container; | ||
|
||
/** | ||
* @param \Boatrace\Sakura\MainTrimmer $trimmer | ||
* @return void | ||
*/ | ||
public function __construct(protected MainTrimmer $trimmer){} | ||
|
||
/** | ||
* @param string $name | ||
* @param array $arguments | ||
* @return string|null | ||
*/ | ||
public function __call(string $name, array $arguments): ?string | ||
{ | ||
return $this->trimmer->$name(...$arguments); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param array $arguments | ||
* @return string|null | ||
*/ | ||
public static function __callStatic(string $name, array $arguments): ?string | ||
{ | ||
return self::getInstance()->$name(...$arguments); | ||
} | ||
|
||
/** | ||
* @return \Boatrace\Sakura\Trimmer | ||
*/ | ||
public static function getInstance(): Trimmer | ||
{ | ||
return self::$instance ?? self::$instance = ( | ||
self::$container ?? self::$container = self::getContainer() | ||
)->get('Trimmer'); | ||
} | ||
|
||
/** | ||
* @return \DI\Container | ||
*/ | ||
public static function getContainer(): Container | ||
{ | ||
$builder = new ContainerBuilder; | ||
$builder->addDefinitions(__DIR__ . '/../config/definitions.php'); | ||
return $builder->build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Boatrace\Sakura\Tests; | ||
|
||
use Boatrace\Sakura\MainTrimmer; | ||
use PHPUnit\Framework\TestCase as PHPUnitTestCase; | ||
|
||
/** | ||
* @author shimomo | ||
*/ | ||
class MainTrimmerTest extends PHPUnitTestCase | ||
{ | ||
/** | ||
* @var \Boatrace\Sakura\MainTrimmer | ||
*/ | ||
protected MainTrimmer $trimmer; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$this->trimmer = new MainTrimmer; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testTrim(): void | ||
{ | ||
$this->assertNull($this->trimmer->trim(null)); | ||
$this->assertSame('競艇', $this->trimmer->trim(' 競艇 ')); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testLtrim(): void | ||
{ | ||
$this->assertNull($this->trimmer->ltrim(null)); | ||
$this->assertSame('競艇 ', $this->trimmer->ltrim(' 競艇 ')); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testRtrim(): void | ||
{ | ||
$this->assertNull($this->trimmer->rtrim(null)); | ||
$this->assertSame(' 競艇', $this->trimmer->rtrim(' 競艇 ')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Boatrace\Sakura\Tests; | ||
|
||
use Boatrace\Sakura\Trimmer; | ||
use PHPUnit\Framework\TestCase as PHPUnitTestCase; | ||
|
||
/** | ||
* @author shimomo | ||
*/ | ||
class TrimmerTest extends PHPUnitTestCase | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function testTrim(): void | ||
{ | ||
$this->assertNull(Trimmer::trim(null)); | ||
$this->assertSame('競艇', Trimmer::trim(' 競艇 ')); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testLtrim(): void | ||
{ | ||
$this->assertNull(Trimmer::ltrim(null)); | ||
$this->assertSame('競艇 ', Trimmer::ltrim(' 競艇 ')); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testRtrim(): void | ||
{ | ||
$this->assertNull(Trimmer::rtrim(null)); | ||
$this->assertSame(' 競艇', Trimmer::rtrim(' 競艇 ')); | ||
} | ||
} |