Skip to content

Commit

Permalink
standardise code to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mulkave committed Jul 23, 2015
1 parent 2887e88 commit e62781e
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 154 deletions.
47 changes: 22 additions & 25 deletions src/Vinelab/Api/Api.php
@@ -1,6 +1,8 @@
<?php namespace Vinelab\Api;
<?php

/**
namespace Vinelab\Api;

/*
* @author Mahmoud Zalt <mahmoud@vinelab.com>
* @author Abed Halawi <abed.halawi@vinelab.com>
*/
Expand All @@ -13,12 +15,10 @@
use Input;

/**
* Class Api
* @package Vinelab\Api
* Class Api.
*/
class Api
{

/**
* @var int
*/
Expand All @@ -44,7 +44,6 @@ class Api
*/
private $config_reader;


/**
* @param \Vinelab\Api\ResponseHandler $response_handler
* @param \Vinelab\Api\ErrorHandler $error_handler
Expand All @@ -63,7 +62,7 @@ public function __construct(
}

/**
* get config file values and store them in attributes
* get config file values and store them in attributes.
*/
private function readConfigFile()
{
Expand All @@ -74,7 +73,7 @@ private function readConfigFile()
}

/**
* Map and respond
* Map and respond.
*
* @param string|mixed $mapper
* @param mixed $data
Expand Down Expand Up @@ -108,7 +107,7 @@ public function respond($mapper, $data)
}

/**
* check if $data is instance of Laravel Paginator
* check if $data is instance of Laravel Paginator.
*
* @param $data
*
Expand All @@ -122,8 +121,8 @@ public function isPaginatorInstance($data)
/**
* Get the formatted data out of the given mapper and data.
*
* @param string|mixed $mapper
* @param mixed $data
* @param string|mixed $mapper
* @param mixed $data
*
* @return array
*/
Expand Down Expand Up @@ -163,17 +162,17 @@ public function data($mapper, $data)
/**
* Resolve a class name of a mapper into the actual instance.
*
* @param string $classname
* @param string $classname
*
* @return mixed
*/
private function resolveMapperClassName($classname)
{
return App::make($this->getMapperNamespace() . $classname);
return App::make($this->getMapperNamespace().$classname);
}

/**
* get the value of mappers_base_namespace from the config file
* get the value of mappers_base_namespace from the config file.
*
* @return string
*/
Expand All @@ -185,7 +184,7 @@ public function getMapperNamespace()
/**
* Check whether the given array is an associative array (key-value).
*
* @param array $array
* @param array $array
*
* @return bool
*/
Expand All @@ -197,8 +196,8 @@ public function isAssocArray($array)
/**
* Get the content only from the response.
*
* @param mixed $mapper
* @param mixed $data
* @param mixed $mapper
* @param mixed $data
*
* @return array
*/
Expand All @@ -220,7 +219,7 @@ public function error()
}

/**
* this function will be accessed as facade from anywhere to get the limit number of data for the endpoint call
* this function will be accessed as facade from anywhere to get the limit number of data for the endpoint call.
*
* @return int
*/
Expand All @@ -238,14 +237,14 @@ public function limit()
}

/**
* get the limit value from the config file which represents the default and the maximum limit
* get the limit value from the config file which represents the default and the maximum limit.
*
* @return int
*/
public function getMaximumLimit()
{
// get the default limit value of results per request from the config file
return (int)$this->limit;
return (int) $this->limit;
}

/**
Expand All @@ -263,25 +262,23 @@ private function validateRequestedLimitValue($request_limit)
$limit = $this->getMaximumLimit();

// check if limit value exceed the allowed predefined default limit value
return ($request_limit <= $limit) ? (int)$request_limit : (int)$limit;
return ($request_limit <= $limit) ? (int) $request_limit : (int) $limit;
}

/**
* override the limit of the config file
* override the limit of the config file.
*
* @param $limit
*/
public function setLimit($limit)
{
$this->limit = (int)$limit;
$this->limit = (int) $limit;
}

/**
* Set the base namespace from which to resolve mappers.
*
* @param string $namespace
*
* @return void
*/
public function setMapperNamespace($namespace)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Vinelab/Api/ApiException.php
@@ -1,10 +1,10 @@
<?php namespace Vinelab\Api;
<?php

namespace Vinelab\Api;

/**
* @author Mahmoud Zalt <mahmoud@vinelab.com>
*/

class ApiException extends \Exception
{

}
6 changes: 4 additions & 2 deletions src/Vinelab/Api/ApiFacadeAccessor.php
@@ -1,6 +1,8 @@
<?php namespace Vinelab\Api;
<?php

/**
namespace Vinelab\Api;

/*
* @author Mahmoud Zalt <mahmoud@vinelab.com>
*/

Expand Down
15 changes: 5 additions & 10 deletions src/Vinelab/Api/ApiServiceProvider.php
@@ -1,6 +1,8 @@
<?php namespace Vinelab\Api;
<?php

/**
namespace Vinelab\Api;

/*
* @author Mahmoud Zalt <mahmoud@vinelab.com>
* @author Abed Halawi <abed.halawi@vinelab.com>
*/
Expand All @@ -9,7 +11,6 @@

class ApiServiceProvider extends ServiceProvider
{

/**
* Indicates if loading of the provider is deferred.
*
Expand All @@ -19,20 +20,16 @@ class ApiServiceProvider extends ServiceProvider

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__ . '/../../config/api.php' => config_path('api.php')
__DIR__.'/../../config/api.php' => config_path('api.php'),
]);
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
Expand All @@ -45,7 +42,6 @@ public function register()
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Api', 'Vinelab\Api\ApiFacadeAccessor');
});

}

/**
Expand All @@ -57,5 +53,4 @@ public function provides()
{
return array('vinelab.api');
}

}
12 changes: 7 additions & 5 deletions src/Vinelab/Api/ErrorHandler.php
@@ -1,6 +1,8 @@
<?php namespace Vinelab\Api;
<?php

/**
namespace Vinelab\Api;

/*
* @author Mahmoud Zalt <mahmoud@vinelab.com>
* @author Abed Halawi <abed.halawi@vinelab.com>
*/
Expand All @@ -10,7 +12,6 @@

class ErrorHandler
{

/**
* @var Responder instance
*/
Expand All @@ -32,6 +33,7 @@ public function __construct(Responder $responder)
* @param int $options
*
* @return \Illuminate\Http\JsonResponse|string
*
* @throws \Vinelab\Api\ApiException
*/
public function handle($exception, $code = 0, $status = 500, $headers = [], $options = 0)
Expand All @@ -45,11 +47,11 @@ public function handle($exception, $code = 0, $status = 500, $headers = [], $opt
} // if not Exception or RuntimeException or a string then throw and API exception
else {
throw new ApiException('Argument 1 passed Vinelab\Api\ErrorHandler::handle() must be an instance of
Exception or RuntimeException or a string, ' . get_class($exception) . ' is given.');
Exception or RuntimeException or a string, '.get_class($exception).' is given.');
}
$response = [
'status' => $status,
'error' => compact('message', 'code')
'error' => compact('message', 'code'),
];

return $this->responder->respond($response, $status, $headers, $options);
Expand Down
7 changes: 4 additions & 3 deletions src/Vinelab/Api/MappableTrait.php
@@ -1,10 +1,11 @@
<?php namespace Vinelab\Api;
<?php

namespace Vinelab\Api;

/**
* @author Mahmoud Zalt <mahmoud@vinelab.com>
*/

trait MappableTrait
{
public abstract function map($data);
abstract public function map($data);
}
11 changes: 5 additions & 6 deletions src/Vinelab/Api/Responder.php
@@ -1,6 +1,8 @@
<?php namespace Vinelab\Api;
<?php

/**
namespace Vinelab\Api;

/*
* @author Mahmoud Zalt <mahmoud@vinelab.com>
*/

Expand All @@ -9,7 +11,6 @@

class Responder
{

/**
* @param \Illuminate\Http\Request $request
*/
Expand Down Expand Up @@ -37,17 +38,15 @@ public function respond($response, $status, $headers, $options)
// whether 'Content-Type' is NULL or equal to anything such as 'application/json' response will be JSON
return Response::json($response, $status, $headers, $options);
}

}

/**
* Get request format from the content type header property
* Get request format from the content type header property.
*
* @return string
*/
public function getRequestFormat()
{
return $this->request->header('Content-Type');
}

}
7 changes: 4 additions & 3 deletions src/Vinelab/Api/ResponseHandler.php
@@ -1,13 +1,13 @@
<?php namespace Vinelab\Api;
<?php

namespace Vinelab\Api;

/**
* @author Mahmoud Zalt <mahmoud@vinelab.com>
* @author Abed Halawi <abed.halawi@vinelab.com>
*/

class ResponseHandler
{

/**
* @var Responder instance
*/
Expand All @@ -33,6 +33,7 @@ public function __construct(Responder $responder)
* @param int $options
*
* @internal param $arguments
*
* @return \Illuminate\Http\JsonResponse
*/
public function respond(
Expand Down

0 comments on commit e62781e

Please sign in to comment.