Commit 75d7349b authored by Thorsten Buss's avatar Thorsten Buss

reformat all files

parent d29a9cf0
This diff is collapsed.
This diff is collapsed.
......@@ -16,10 +16,8 @@ class CartServiceProvider extends ServiceProvider {
*
* @return void
*/
public function register()
{
$this->app['cart'] = $this->app->share(function($app)
{
public function register() {
$this->app['cart'] = $this->app->share(function ($app) {
$storage = $app['session'];
$events = $app['events'];
$instanceName = 'cart';
......@@ -39,8 +37,7 @@ class CartServiceProvider extends ServiceProvider {
*
* @return array
*/
public function provides()
{
public function provides() {
return array();
}
}
......@@ -4,8 +4,7 @@ use Illuminate\Support\Facades\Facade;
class CartFacade extends Facade {
protected static function getFacadeAccessor()
{
return 'cart';
}
protected static function getFacadeAccessor() {
return 'cart';
}
}
\ No newline at end of file
......@@ -9,96 +9,85 @@
class Helpers {
const ROUND_MODE_HALF_UP = PHP_ROUND_HALF_UP;
const ROUND_MODE_HALF_DOWN = PHP_ROUND_HALF_DOWN;
const ROUND_MODE_HALF_EVEN = PHP_ROUND_HALF_EVEN;
const ROUND_MODE_HALF_ODD = PHP_ROUND_HALF_ODD;
const ROUND_MODE_HALF_UP = PHP_ROUND_HALF_UP;
const ROUND_MODE_HALF_DOWN = PHP_ROUND_HALF_DOWN;
const ROUND_MODE_HALF_EVEN = PHP_ROUND_HALF_EVEN;
const ROUND_MODE_HALF_ODD = PHP_ROUND_HALF_ODD;
const DEFAULT_ROUND_MODE = self::ROUND_MODE_HALF_UP;
const DEFAULT_ROUND_MODE = self::ROUND_MODE_HALF_UP;
/**
* normalize price
*
* @param $price
* @return int
*/
public static function normalizePrice($price)
{
return (is_string($price)) ? intval($price) : $price;
}
/**
* normalize price
*
* @param $price
* @return int
*/
public static function normalizePrice($price) {
return (is_string($price)) ? intval($price) : $price;
}
/**
* @param $value
* @param int $mode
*/
public static function intval($value, $mode = self::DEFAULT_ROUND_MODE) {
return self::round($value, 0, $mode);
}
* @param $value
* @param int $mode
*/
public static function intval($value, $mode = self::DEFAULT_ROUND_MODE) {
return self::round($value, 0, $mode);
}
/**
* @param $value
* @param int $precision
* @param int $mode
*/
public static function round($value, $precision = 0, $mode = self::DEFAULT_ROUND_MODE) {
return round($value, $precision, $mode);
}
* @param $value
* @param int $precision
* @param int $mode
*/
public static function round($value, $precision = 0, $mode = self::DEFAULT_ROUND_MODE) {
return round($value, $precision, $mode);
}
/**
* normalize percentage
*
* @param $val
* @return float
*/
public static function normalizePercentage($val)
{
return (is_string($val)) ? floatval($val) : $val;
}
/**
* normalize percentage
*
* @param $val
* @return float
*/
public static function normalizePercentage($val) {
return (is_string($val)) ? floatval($val) : $val;
}
/**
* check if array is multi dimensional array
* This will only check the first element of the array if it is still an array
* to decide that it is a multi dimensional, if you want to check the array strictly
* with all on its element, flag the second argument as true
*
* @param $array
* @param bool $recursive
* @return bool
*/
public static function isMultiArray($array, $recursive = false)
{
if( $recursive )
{
return (count($array) == count($array, COUNT_RECURSIVE)) ? false : true;
}
else
{
foreach ($array as $k => $v)
{
if (is_array($v))
{
return true;
}
else
{
return false;
}
}
/**
* check if array is multi dimensional array
* This will only check the first element of the array if it is still an array
* to decide that it is a multi dimensional, if you want to check the array strictly
* with all on its element, flag the second argument as true
*
* @param $array
* @param bool $recursive
* @return bool
*/
public static function isMultiArray($array, $recursive = false) {
if ($recursive) {
return (count($array) == count($array, COUNT_RECURSIVE)) ? false : true;
} else {
foreach ($array as $k => $v) {
if (is_array($v)) {
return true;
} else {
return false;
}
}
}
}
}
}
/**
* check if variable is set and has value, return a default value
*
* @param $var
* @param bool|mixed $default
* @return bool|mixed
*/
public static function issetAndHasValueOrAssignDefault(&$var, $default = false)
{
if( (isset($var)) && ($var!='') ) return $var;
/**
* check if variable is set and has value, return a default value
*
* @param $var
* @param bool|mixed $default
* @return bool|mixed
*/
public static function issetAndHasValueOrAssignDefault(&$var, $default = false) {
if ((isset($var)) && ($var != '')) return $var;
return $default;
}
return $default;
}
}
\ No newline at end of file
......@@ -11,9 +11,8 @@ use Illuminate\Support\Collection;
class ItemAttributeCollection extends Collection {
public function __get($name)
{
if( $this->has($name) ) return $this->get($name);
return null;
}
public function __get($name) {
if ($this->has($name)) return $this->get($name);
return null;
}
}
\ No newline at end of file
......@@ -11,85 +11,72 @@ use Illuminate\Support\Collection;
class ItemCollection extends Collection {
/**
* get the sum of price
*
* @return mixed|null
*/
public function getPriceSum()
{
return $this->price * $this->quantity;
}
/**
* get the sum of price
*
* @return mixed|null
*/
public function getPriceSum() {
return $this->price * $this->quantity;
}
public function __get($name)
{
if( $this->has($name) ) return $this->get($name);
return null;
}
public function __get($name) {
if ($this->has($name)) return $this->get($name);
return null;
}
/**
* check if item has conditions
*
* @return bool
*/
public function hasConditions()
{
if( ! isset($this['conditions']) ) return false;
if( is_array($this['conditions']) )
{
return count($this['conditions']) > 0;
}
$conditionInstance = "Darryldecode\\Cart\\CartCondition";
if( $this['conditions'] instanceof $conditionInstance ) return true;
/**
* check if item has conditions
*
* @return bool
*/
public function hasConditions() {
if (!isset($this['conditions'])) return false;
if (is_array($this['conditions'])) {
return count($this['conditions']) > 0;
}
$conditionInstance = "Darryldecode\\Cart\\CartCondition";
if ($this['conditions'] instanceof $conditionInstance) return true;
return false;
}
return false;
}
/**
* get the single price in which conditions are already applied
*
* @return mixed|null
*/
public function getPriceWithConditions()
{
$originalPrice = $this->price;
$newPrice = 0;
$processed = 0;
/**
* get the single price in which conditions are already applied
*
* @return mixed|null
*/
public function getPriceWithConditions() {
$originalPrice = $this->price;
$newPrice = 0;
$processed = 0;
if( $this->hasConditions() )
{
if( is_array($this->conditions) )
{
foreach($this->conditions as $condition)
{
if( $condition->getTarget() === 'item' )
{
( $processed > 0 ) ? $toBeCalculated = $newPrice : $toBeCalculated = $originalPrice;
$newPrice = $condition->applyCondition($toBeCalculated);
$processed++;
}
}
}
else
{
if( $this['conditions']->getTarget() === 'item' )
{
$newPrice = $this['conditions']->applyCondition($originalPrice);
}
}
if ($this->hasConditions()) {
if (is_array($this->conditions)) {
foreach ($this->conditions as $condition) {
if ($condition->getTarget() === 'item') {
($processed > 0) ? $toBeCalculated = $newPrice : $toBeCalculated = $originalPrice;
$newPrice = $condition->applyCondition($toBeCalculated);
$processed++;
}
}
} else {
if ($this['conditions']->getTarget() === 'item') {
$newPrice = $this['conditions']->applyCondition($originalPrice);
}
}
return $newPrice;
}
return $originalPrice;
}
return $newPrice;
}
return $originalPrice;
}
/**
* get the sum of price in which conditions are already applied
*
* @return mixed|null
*/
public function getPriceSumWithConditions()
{
return $this->getPriceWithConditions() * $this->quantity;
}
/**
* get the sum of price in which conditions are already applied
*
* @return mixed|null
*/
public function getPriceSumWithConditions() {
return $this->getPriceWithConditions() * $this->quantity;
}
}
<?php namespace Darryldecode\Cart\Validators;
use Symfony\Component\Translation\Translator;
use Illuminate\Validation\Factory;
......@@ -8,45 +9,40 @@ use Illuminate\Validation\Factory;
* Date: 1/16/2015
* Time: 10:59 AM
*/
abstract class Validator {
protected static $factory;
protected static $factory;
public static function instance()
{
if ( ! static::$factory)
{
$translator = new Translator('en');
static::$factory = new Factory($translator);
}
public static function instance() {
if (!static::$factory) {
$translator = new Translator('en');
static::$factory = new Factory($translator);
}
return static::$factory;
}
return static::$factory;
}
public static function __callStatic($method, $args)
{
$instance = static::instance();
public static function __callStatic($method, $args) {
$instance = static::instance();
switch (count($args))
{
case 0:
return $instance->$method();
switch (count($args)) {
case 0:
return $instance->$method();
case 1:
return $instance->$method($args[0]);
case 1:
return $instance->$method($args[0]);
case 2:
return $instance->$method($args[0], $args[1]);
case 2:
return $instance->$method($args[0], $args[1]);
case 3:
return $instance->$method($args[0], $args[1], $args[2]);
case 3:
return $instance->$method($args[0], $args[1], $args[2]);
case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);
case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);
default:
return call_user_func_array(array($instance, $method), $args);
}
}
default:
return call_user_func_array(array($instance, $method), $args);
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -9,49 +9,44 @@
use Darryldecode\Cart\Cart;
use Mockery as m;
require_once __DIR__.'/helpers/SessionMock.php';
require_once __DIR__ . '/helpers/SessionMock.php';
class ItemTest extends PHPUnit_Framework_TestCase
{
class ItemTest extends PHPUnit_Framework_TestCase {
/**
* @var Darryldecode\Cart\Cart
*/
protected $cart;
/**
* @var Darryldecode\Cart\Cart
*/
protected $cart;
public function setUp()
{
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
$events->shouldReceive('fire');
public function setUp() {
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
$events->shouldReceive('fire');
$this->cart = new Cart(
new SessionMock(),
$events,
'shopping',
'SAMPLESESSIONKEY'
);
}
$this->cart = new Cart(
new SessionMock(),
$events,
'shopping',
'SAMPLESESSIONKEY'
);
}
public function tearDown()
{
m::close();
}
public function tearDown() {
m::close();
}
public function test_item_get_sum_price_using_property()
{
$this->cart->add(455, 'Sample Item', 10099, 2, array());
public function test_item_get_sum_price_using_property() {
$this->cart->add(455, 'Sample Item', 10099, 2, array());
$item = $this->cart->get(455);
$item = $this->cart->get(455);
$this->assertEquals(20198, $item->getPriceSum(), 'Item summed price should be 20198');
}
$this->assertEquals(20198, $item->getPriceSum(), 'Item summed price should be 20198');
}
public function test_item_get_sum_price_using_array_style()
{
$this->cart->add(455, 'Sample Item', 10099, 2, array());
public function test_item_get_sum_price_using_array_style() {
$this->cart->add(455, 'Sample Item', 10099, 2, array());
$item = $this->cart->get(455);
$item = $this->cart->get(455);
$this->assertEquals(20198, $item->getPriceSum(), 'Item summed price should be 20198');
}
$this->assertEquals(20198, $item->getPriceSum(), 'Item summed price should be 20198');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: darryl
* Date: 1/12/2015
* Time: 10:23 PM
*/
class SessionMock {
protected $session = array();
protected $session = array();
public function has($key)
{
return isset($this->session[$key]);
}
public function has($key) {
return isset($this->session[$key]);
}
public function get($key)
{
return (isset($this->session[$key])) ? $this->session[$key] : null;
}
public function get($key) {
return (isset($this->session[$key])) ? $this->session[$key] : null;
}
public function put($key, $value)
{
$this->session[$key] = $value;
}
public function put($key, $value) {
$this->session[$key] = $value;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment