germania-kg/orders

Interfaces and Traits for Order numbers

1.0.4 2022-03-30 10:17 UTC

This package is auto-updated.

Last update: 2024-04-29 03:47:15 UTC


README

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

Installation with Composer

$ composer require germania-kg/orders

Interfaces

OrderNumberProviderInterface

public function getOrderNumber()

OrderNumberAwareInterface

extends OrderNumberProviderInterface
public function setOrderNumber( $order_number )

Traits

OrderNumberProviderTrait

Objects using this trait will provide a order_number attribute and a getOrderNumber getter method, as outlined here:

public $order_number;
public function getOrderNumber()

OrderNumberAwareTrait

Objects using this trait will provide anything that OrderNumberProviderTrait provides, and additionally a setter method setOrderNumber which accepts anything; if OrderNumberProviderInterface given here, getOrderNumber method will be called to obtain the ID to use. Roughly outlined:

use OrderNumberProviderTrait;
public function setOrderNumber( $order_number )

Examples

<?php
use Germania\Orders\OrderNumberProviderInterface;
use Germania\Orders\OrderNumberProviderTrait;

class MyOrder implements OrderNumberProviderInterface
{
	use OrderNumberProviderTrait;
	
	public function __construct( order_number )
	{
		$this->order_number = order_number;
	}
}

$order = new MyOrder( 99 );
echo $order->getOrderNumber(); // 99
<?php
use Germania\Orders\OrderNumberAwareInterface;
use Germania\Orders\OrderNumberAwareTrait;

class MyOrder implements OrderNumberAwareInterface
{
	use OrderNumberAwareTrait;
}

$order  = new MyOrder;
$order->setOrderNumber( 34 );
echo $order->getOrderNumber(); // 34

Development

$ git clone https://github.com/GermaniaKG/Orders.git
$ cd Orders
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:

$ composer test
# or
$ vendor/bin/phpunit