Skip to content

Commit

Permalink
Merge pull request #24 from ingrammicro/fix-small-code-style-improvem…
Browse files Browse the repository at this point in the history
…ents

Fix small code style improvements
  • Loading branch information
marcserrat authored Mar 21, 2019
2 parents 6057883 + 3e9738b commit aa3cd7f
Show file tree
Hide file tree
Showing 122 changed files with 236 additions and 288 deletions.
4 changes: 0 additions & 4 deletions examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class MyAppRequests extends \Connect\RequestsProcessor
{

public function processRequest($req)
{
$req->asset->tiers['customer']->name;
Expand Down Expand Up @@ -52,12 +51,9 @@ public function processRequest($req)


try {

$rp = new MyAppRequests();
$rp->process();

} catch (Exception $e) {
\Connect\Logger::get()->error($e->getMessage());
\Connect\Logger::get()->dump();
}

3 changes: 1 addition & 2 deletions src/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ class Account extends Model
*/

public $contact_info;

}
}
2 changes: 1 addition & 1 deletion src/Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class Activation extends Model
* @var
*/
public $link;
}
}
2 changes: 1 addition & 1 deletion src/ActivationTemplateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public function __construct($templateid)
{
$this->templateid = $templateid;
}
}
}
3 changes: 1 addition & 2 deletions src/ActivationTileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public function __construct($msg = null)
$this->activationTile = $msg;
}
}

}
}
3 changes: 1 addition & 2 deletions src/Agreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class Agreement extends Model
* @var
*/
public $name;

}
}
2 changes: 1 addition & 1 deletion src/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ public function getItemByMPN($mpn)

return ($item) ? $item : null;
}
}
}
2 changes: 1 addition & 1 deletion src/Assignee.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class Assignee extends Model
* @var
*/
public $name;
}
}
3 changes: 1 addition & 2 deletions src/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class Choice extends Model
* @var
*/
public $label;

}
}
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function __construct($source)
case 'object':
case 'array':
break;
default :
default:
throw new ConfigException("Invalid argument for \\Connect\\Config class constructor: " . gettype($source));
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public function setRuntimeServices($runtimeServices)

public function setProducts($product)
{
if(is_string($product)) {
if (is_string($product)) {
$product = [$product];
}

Expand Down
2 changes: 1 addition & 1 deletion src/ConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public function __construct($message, $prop = null)
$this->message = $message . " for property " . $prop;
}
}
}
}
2 changes: 1 addition & 1 deletion src/ConfigPropertyMissed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public function __construct($prop)
{
parent::__construct('Value is not set ', $prop);
}
}
}
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public function getParameterByID($id)

return ($param) ? $param : null;
}
}
}
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class Connection extends Model
* @var Vendor
*/
public $vendor;
}
}
3 changes: 1 addition & 2 deletions src/Constraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ class Constraints extends Model
* @var Choice[]
*/
public $choices;

}
}
2 changes: 1 addition & 1 deletion src/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class Contact extends Model
* @var PhoneNumber
*/
public $phone_number;
}
}
1 change: 0 additions & 1 deletion src/ContactInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ class ContactInfo extends Model
public $postal_code;
public $state;
}

3 changes: 1 addition & 2 deletions src/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ class Contract extends Model
* @var Marketplace
*/
public $marketplace;

}
}
3 changes: 1 addition & 2 deletions src/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ class Creator extends Model
* @var
*/
public $name;

}
}
2 changes: 1 addition & 1 deletion src/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class Customer extends Model
* @var ContactInfo
*/
public $contact_info;
}
}
2 changes: 1 addition & 1 deletion src/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class Events extends Model
public $inquired;
public $updated;
public $created;
}
}
1 change: 1 addition & 0 deletions src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Exception extends \Exception
*/
public function __construct($message, $code = 'unknown', $object = null)
{
parent::__construct();
$this->code = $code;
$this->message = $message;
$this->object = $object;
Expand Down
2 changes: 1 addition & 1 deletion src/Fail.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public function __construct($message = null)
{
parent::__construct($message ? $message : 'Request processing failed', 'fail');
}
}
}
67 changes: 40 additions & 27 deletions src/FulfillmentAutomation.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ public function process()
protected function dispatchTierConfig($tierConfigRequest)
{
try {
if ($this->config->products && !in_array($tierConfigRequest->configuration->product->id,
$this->config->products)) {
if ($this->config->products && !in_array(
$tierConfigRequest->configuration->product->id,
$this->config->products
)) {
return 'Invalid product';
}

Expand All @@ -144,30 +146,35 @@ protected function dispatchTierConfig($tierConfigRequest)
}

if ($msg instanceof ActivationTemplateResponse) {
$this->sendRequest('POST', '/tier/config-requests/' . $tierConfigRequest->id . '/approve',
'{"template": {"id": "' . $msg->templateid . '"}}');
$this->sendRequest(
'POST',
'/tier/config-requests/' . $tierConfigRequest->id . '/approve',
'{"template": {"id": "' . $msg->templateid . '"}}'
);
$processingResult = 'succeed (Activated using template ' . $msg->templateid . ')';
} else {
$this->sendRequest('POST', '/tier/config-requests/' . $tierConfigRequest->id . '/approve',
'{"template": {"representation": "' . $msg->activationTile . '"}}');
$this->sendRequest(
'POST',
'/tier/config-requests/' . $tierConfigRequest->id . '/approve',
'{"template": {"representation": "' . $msg->activationTile . '"}}'
);
$processingResult = 'succeed (' . $msg->activationTile . ')';
}

} catch (Inquire $e) {
// update parameters and move to inquire
$this->updateTierConfigRequestParameters($tierConfigRequest, $e->params);//WORKING HERE!
$this->sendRequest('POST', '/tier/config-requests/' . $tierConfigRequest->id . '/inquire', '{}');
$processingResult = 'inquire';

} catch (Fail $e) {
// fail request
$this->sendRequest('POST', '/tier/config-requests/' . $tierConfigRequest->id . '/fail',
'{"reason": "' . $e->getMessage() . '"}');
$this->sendRequest(
'POST',
'/tier/config-requests/' . $tierConfigRequest->id . '/fail',
'{"reason": "' . $e->getMessage() . '"}'
);
$processingResult = 'fail';

} catch (Skip $e) {
$processingResult = 'skip';

}

$this->logger->info("Finished processing of Tier Config Request with ID=" . $tierConfigRequest->id . " result=" . $processingResult);
Expand Down Expand Up @@ -198,30 +205,35 @@ protected function dispatch($request)
}

if ($msg instanceof ActivationTemplateResponse) {
$this->sendRequest('POST', '/requests/' . $request->id . '/approve',
'{"template_id": "' . $msg->templateid . '"}');
$this->sendRequest(
'POST',
'/requests/' . $request->id . '/approve',
'{"template_id": "' . $msg->templateid . '"}'
);
$processingResult = 'succeed (Activated using template ' . $msg->templateid . ')';
} else {
$this->sendRequest('POST', '/requests/' . $request->id . '/approve',
'{"activation_tile": "' . $msg->activationTile . '"}');
$this->sendRequest(
'POST',
'/requests/' . $request->id . '/approve',
'{"activation_tile": "' . $msg->activationTile . '"}'
);
$processingResult = 'succeed (' . $msg->activationTile . ')';
}

} catch (Inquire $e) {
// update parameters and move to inquire
$this->updateParameters($request, $e->params);
$this->sendRequest('POST', '/requests/' . $request->id . '/inquire', '{}');
$processingResult = 'inquire';

} catch (Fail $e) {
// fail request
$this->sendRequest('POST', '/requests/' . $request->id . '/fail',
'{"reason": "' . $e->getMessage() . '"}');
$this->sendRequest(
'POST',
'/requests/' . $request->id . '/fail',
'{"reason": "' . $e->getMessage() . '"}'
);
$processingResult = 'fail';

} catch (Skip $e) {
$processingResult = 'skip';

}

$this->logger->info("Finished processing of request ID=" . $request->id . " result=" . $processingResult);
Expand Down Expand Up @@ -341,8 +353,10 @@ public function renderTemplate($templateId, $request)
*/
public function getTierConfigByProduct($tierId, $productId)
{
$body = $this->sendRequest('GET',
'/tier/config-requests?status=approved&configuration__product__id=' . $productId . '&configuration__account__id=' . $tierId);
$body = $this->sendRequest(
'GET',
'/tier/config-requests?status=approved&configuration__product__id=' . $productId . '&configuration__account__id=' . $tierId
);
$model = Model::modelize('tierconfigrequests', json_decode($body));
if (count($model) > 0) {
return $model[0]->configuration;
Expand All @@ -360,14 +374,13 @@ public function getTierConfigByProduct($tierId, $productId)
public function getTierParameterByProductAndTierId($parameterId, $tierId, $productId)
{
$tierConfig = $this->getTierConfigByProduct($tierId, $productId);
if(!$tierConfig){
if (!$tierConfig) {
return null;
}
$param = current(array_filter($tierConfig->params, function (Param $param) use ($parameterId) {
return ($param->id === $parameterId);
}));

return ($param) ? $param : null;

}
}
}
2 changes: 1 addition & 1 deletion src/FulfillmentAutomationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ interface FulfillmentAutomationInterface
public function processRequest($request);

public function processTierConfigRequest($tierConfigRequest);
}
}
2 changes: 1 addition & 1 deletion src/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class Hub extends Model
* @var
*/
public $uuid;
}
}
2 changes: 1 addition & 1 deletion src/Inquire.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public function __construct($params)
$this->params = $params;
parent::__construct('Activation parameters are required', 'inquiry');
}
}
}
2 changes: 1 addition & 1 deletion src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class Item extends Model
* @var Renewal
*/
public $renewal;
}
}
3 changes: 1 addition & 2 deletions src/Listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ class Listing extends Model
* @var Provider;
*/
public $provider;

}
}
2 changes: 1 addition & 1 deletion src/Logger/LogRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public function __construct($level, $message, $time = 0)
$this->message = $message;
$this->time = ($time === 0) ? time() : $time;
}
}
}
2 changes: 1 addition & 1 deletion src/Logger/LogSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ public function count()
{
return count($this->sessionLog);
}
}
}
2 changes: 1 addition & 1 deletion src/Logger/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ public function setLogLevel($level);
* Dump session log to current log, and reset session
*/
public function dump();
}
}
2 changes: 1 addition & 1 deletion src/Marketplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class Marketplace extends Model
public $id;
public $name;
public $icon;
}
}
2 changes: 1 addition & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public function __construct($message, $code, $object = null)
{
parent::__construct($message, $code, $object);
}
}
}
Loading

0 comments on commit aa3cd7f

Please sign in to comment.