Skip to content

Commit

Permalink
Version 1.1 is ready
Browse files Browse the repository at this point in the history
* Bump up the PHP version
* Bump up PHPUnit version
* Used a PHP 5.6 Constant expressions
* Fixed some typos
* Added more tests
* Updated the README.md file
  • Loading branch information
SamAsEnd authored Feb 19, 2017
1 parent 1498625 commit 4c93e60
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 33 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1

install: travis_retry composer install --no-interaction --prefer-source

script: phpunit --coverage-clover=coverage.clover
script: vendor/bin/phpunit --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
Andegna Geezify
Andegna Geezify ![From Ethiopia](https://img.shields.io/badge/From-Ethiopia-brightgreen.svg)
===============

[![Build Status](https://travis-ci.org/andegna/geezify.svg?branch=master)](https://travis-ci.org/andegna/geezify)
[![StyleCI](https://styleci.io/repos/68031629/shield?branch=master)](https://styleci.io/repos/68031629)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/andegna/geezify/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/andegna/geezify/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/andegna/geezify/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/andegna/geezify/?branch=develop)
[![Code Coverage](https://scrutinizer-ci.com/g/andegna/geezify/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/andegna/geezify/?branch=master)
[![Total Downloads](https://poser.pugx.org/andegna/geezify/d/total.svg)](https://packagist.org/packages/andegna/geezify)
[![Latest Stable Version](https://poser.pugx.org/andegna/geezify/v/stable.svg)](https://packagist.org/packages/andegna/geezify)
[![Latest Unstable Version](https://poser.pugx.org/andegna/geezify/v/unstable.svg)](https://packagist.org/packages/andegna/geezify)
[![License](https://poser.pugx.org/andegna/geezify/license.svg)](https://packagist.org/packages/andegna/geezify)

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/a3519698-fee9-494c-adbb-c5c2f8abc422/big.png)](https://insight.sensiolabs.com/projects/a3519698-fee9-494c-adbb-c5c2f8abc422)

This package is a simple library to convert ascii number '**3456**' to geez number '**፴፬፻፶፮**'.
This package is a library to convert ascii number like '**3456**' to geez number '**፴፬፻፶፮**' and vise versa.

Installation
------------
> Ge'ez (ግዕዝ) is an ancient South Semitic language that originated in Eritrea and the northern region of Ethiopia in the Horn of Africa. It later became the official language of the Kingdom of Aksum and Ethiopian imperial court.
click [here](https://en.wikipedia.org/wiki/Ge%27ez) to read more.

### Prerequisites
geezify requires PHP 5.4 or greater.
Prerequisites
-------------
`geezify` requires **PHP** 5.6 or greater.

### Setup through composer
Installation
------------
```sh
composer require andegna/geezify
```

A simple example
> If you never used `composer` before, please check out
> [this link](https://getcomposer.org)
> before you write any **PHP** code again!
Usage
----------------
```php
<?php
Expand All @@ -36,17 +43,17 @@ use Andegna\Geez\Geezify;

$geez = Geezify::create();

echo $geez->toGeez(123) . PHP_EOL; // ፻፳፫
echo $geez->toGeez(1234) . PHP_EOL; // ፲፪፻፴፬
echo $geez->toGeez(1986) . PHP_EOL; // ፲፱፻፹፮
echo $geez->toGeez(123) . PHP_EOL; // ፻፳፫
echo $geez->toGeez(1234) . PHP_EOL; // ፲፪፻፴፬
echo $geez->toGeez(1986) . PHP_EOL; // ፲፱፻፹፮
echo $geez->toGeez(1000000) . PHP_EOL; // ፻፼

// or you can even do the reverse

echo $geez->toAscii('፻፳፫') . PHP_EOL; // 123
echo $geez->toAscii('፲፪፻፴፬') . PHP_EOL; // 1234
echo $geez->toAscii('፲፱፻፹፮') . PHP_EOL; // 1986
echo $geez->toAscii('፻፼') . PHP_EOL; // 1000000
echo $geez->toAscii('፻፳፫') . PHP_EOL; // 123
echo $geez->toAscii('፲፪፻፴፬') . PHP_EOL; // 1234
echo $geez->toAscii('፲፱፻፹፮') . PHP_EOL; // 1986
echo $geez->toAscii('፻፼') . PHP_EOL; // 1000000
```

License
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
],
"require": {
"php": ">=5.4|7.*"
"php": ">=5.6|7.*"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/AsciiConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function parse($geez_number)
protected function calculate(Queue $parsed)
{
$calculator = new GeezCalculator($parsed);
$calculator->calculator();
$calculator->calculate();

return $calculator->getCalculated();
}
Expand Down
6 changes: 2 additions & 4 deletions src/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ abstract class Converter
// space, it's just an empty string
const EMPTY_CHARACTER = '';

// PHP never thought of declaring (const | define) arrays till 5.6
// This is the second best thing for 5.4
public static $GEEZ_NUMBERS = [
const GEEZ_NUMBERS = [
0 => '', '', '', '', '', '', '', '', '', '', '',
20 => '',
30 => '',
Expand Down Expand Up @@ -66,7 +64,7 @@ protected function isGeezNumberHundred($geez_number)
*/
protected function isGeezNumber($geez_number, $number)
{
return $geez_number === self::$GEEZ_NUMBERS[$number];
return $geez_number === self::GEEZ_NUMBERS[$number];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/GeezConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function getGeezNumberOfTheBlock($number, $index)
$once = (int) $block[1];

return
static::$GEEZ_NUMBERS[($tenth * 10)].static::$GEEZ_NUMBERS[$once];
static::GEEZ_NUMBERS[($tenth * 10)].static::GEEZ_NUMBERS[$once];
}

/**
Expand Down Expand Up @@ -204,9 +204,9 @@ protected function getGeezSeparator($bet)
if ($this->isZero($bet)) {
return static::EMPTY_CHARACTER;
} elseif ($this->isOdd($bet)) {
return static::$GEEZ_NUMBERS[100];
return static::GEEZ_NUMBERS[100];
} else {
return static::$GEEZ_NUMBERS[10000];
return static::GEEZ_NUMBERS[10000];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Helper/GeezCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(Queue $queue)
/**
* Do the magic.
*/
public function calculator()
public function calculate()
{
$this->resetSubTotalToZero();

Expand Down Expand Up @@ -118,7 +118,7 @@ protected function processBySeparator($block, $separator)
*
* @param $block
*
* @return int
* @return void
*/
protected function addToTotal($block)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/GeezParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function getCharacterAt($geez_number, $index)
*/
protected function getAsciiNumber($geez_number)
{
$ascii_number = array_search($geez_number, Converter::$GEEZ_NUMBERS, true);
$ascii_number = array_search($geez_number, Converter::GEEZ_NUMBERS, true);

if ($ascii_number === false) {
throw new NotGeezArgumentException($geez_number);
Expand Down
48 changes: 48 additions & 0 deletions tests/GeezifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

namespace Andegna\Geez\PHPUnit;

use Andegna\Geez\Converter\AsciiConverter;
use Andegna\Geez\Converter\GeezConverter;
use Andegna\Geez\Geezify;
use Prophecy\Prophet;

class GeezifyTest extends TestCase
{
/** @var Prophet */
protected $prophet;

protected function setup()
{
$this->prophet = new Prophet();
}

protected function tearDown()
{
$this->prophet->checkPredictions();
}

public function test_random_numbers()
{
$geezify = Geezify::create();
Expand All @@ -19,4 +35,36 @@ public function test_random_numbers()
$this->assertEquals($random_number, $ascii_number);
}
}

public function test_geezify_build_process()
{
// let prophesize ;)
$geez = $this->prophet->prophesize(GeezConverter::class);
$ascii = $this->prophet->prophesize(AsciiConverter::class);

// build out thing
$geezify = new Geezify($geez->reveal(), $ascii->reveal());

// promise
$geez->convert(123)->willReturn('giber gaber');
$ascii->convert('lorem ipsum')->willReturn(321);

// assert the response
$this->assertEquals(321, $geezify->toAscii('lorem ipsum'));
$this->assertEquals('giber gaber', $geezify->toGeez(123));
}

public function test_setter_and_getters()
{
$geezify = Geezify::create();

$geez_dummy = $this->prophet->prophesize(GeezConverter::class)->reveal();
$ascii_dummy = $this->prophet->prophesize(AsciiConverter::class)->reveal();

$geezify->setGeezConverter($geez_dummy);
$geezify->setAsciiConverter($ascii_dummy);

$this->assertEquals($geez_dummy, $geezify->getGeezConverter());
$this->assertEquals($ascii_dummy, $geezify->getAsciiConverter());
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Andegna\Geez\PHPUnit;

class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends \PHPUnit\Framework\TestCase
{
public function geezNumberTestDataProvider()
{
Expand Down

0 comments on commit 4c93e60

Please sign in to comment.