oliver-noth/arabic-roman-number-converter

Takes an arabic or roman numeral and returns the corresponding conversion.

v1.0.2 2021-11-01 17:15 UTC

This package is auto-updated.

Last update: 2024-04-29 05:05:35 UTC


README

ArabicRomanNumberConverter is a composer package, which converts an arabic or roman numeral to the opposite numeral.

Latest Stable Version Minimum PHP Version Type Coverage Semantic Versioning MIT license

Table of contents

  1. Getting started
    1. Requirements
    2. Installation
  2. Usage
    1. Basic
    2. Further
  3. Docker
    1. Prerequisites
    2. Setup
    3. Create and run docker container
    4. Unit tests
    5. Digging deeper
  4. Authors

Getting Started

Requirements

  • Your local machine must run with at least PHP 8.0
  • Be sure to have composer installed

Installation

Use composer to download and install ArabicRomanNumberConverter.

You can add ArabicRomanNumberConverter as a local, per-project dependency to your project:

$ composer require oliver-noth/arabic-roman-number-converter

If you only need ArabicRomanNumberConverter during development, then you should add it as a development-time dependency:

$ composer require --dev oliver-noth/arabic-roman-number-converter

Usage

Basic

First instantiate a new number converter

$factory = new \OliverNoth\ArabicRomanNumberConverter\Main\Factory();

/**
 * Numeral can be passed in different ways:
 */

// 1.) Pass it to the constructor
$numberConverter = $factory->createNumberConverter('MCMLXVIII');

// 2.) Pass it to the setter method
$numberConverter = $factory->createNumberConverter()->setCandidate('MCMLXVIII');

then get the converted numeral

$converted = $numberConverter->convert(); // $converted will be (int) 1968

or get another conversion without creating a new number converter by passing in another numeral

$converted = $numberConverter->convert(1968); // $converted will be (string) 'MCMLXVIII'

You can get conversion notes (especially those from failed validation)

$notes = $numberConverter->getConversionNotes();

Further

See example/basic-usage.php to get an idea on how to use ArabicRomanNumberConverter in your project.

Docker

Set up a docker container on your local machine using ddev.

Prerequisites

Setup

Install ddev (using Homebrew/Linuxbrew is recommended):

$ brew tap drud/ddev && brew install ddev

Create and cd into your project directory (replace folder name `<PATH-TO-YOUR-PROJECT-DIRECTORY>/my-project` according to your needs):

$ mkdir -p <PATH-TO-YOUR-PROJECT-DIRECTORY>/my-project
$ cd <PATH-TO-YOUR-PROJECT-DIRECTORY>/my-project

Create a new docker container

Configure a ddev docker container (replace project-name my-project according to your needs):

$ ddev config --project-name=my-project --project-type=php --php-version=8.0 --docroot="" --create-docroot --disable-settings-management --http-port=8088 --https-port=44388

Create configured container and clone composer package into it:
IMPORTANT: Eventually arising question `Warning: ALL EXISTING CONTENT of the project root (~/my-project) will be deleted` must be answered with 'yes'

$ ddev composer create oliver-noth/arabic-roman-number-converter

Create index.php in document root of created container:

$ ddev exec chmod 755 example/write-index.sh && ddev exec ./example/write-index.sh

Finally start created container

$ ddev start

Once you have started the container, your project can be reached at `http://my-project.ddev.site:8088.<br> NOTE: Subdomain my-project` should be replaced with project-name you have chosen before.

Unit tests

This package is completely unit tested. You can run them in the created container:

$ ddev exec vendor/bin/phpunit

Displaying a code coverage summary needs enabling a code coverage driver. Use xdebug, check it and get the summary:

$ ddev xdebug
$ ddev xdebug status
$ ddev exec vendor/bin/phpunit --coverage-text

NOTE: Although code coverage is at 100%, maybe the container displays a smaller coverage.
Running it on your local machine (assuming a code coverage driver like xdebug is installed) in your project directory should display 100%. Working on a fix...

$ vendor/bin/phpunit --coverage-text

Digging deeper

For instance managing the webserver behaviour of the container acting as such could be done by entering the container:

$ ddev ssh

MORE: Complete documentation can be found at ddev.readthedocs.io

Authors