Skip to content

Instantly share code, notes, and snippets.

View non-senses's full-sized avatar

Nico Andrade non-senses

View GitHub Profile
<?php
namespace Roofr\Proposal\Commands;
use Illuminate\Console\Command;
const PROPOSALTEAMIDENTIFIER = '@PRO-[1234,5678]';
class NicDev extends Command
{
<?php
/**
* Unlock a specific type of order. Unusually unlock after the confirm has been completed
*
* @param int $orderId Id of the object you unlock
* @return bool True on success
* @throws LockException
* @throws \Exception
*/
public function unlock($orderId, $userId)
<?php
public function unlock($orderId, $userId)
{
if (empty($this->type)) {
throw new LockException("Can not unlock the order: type is mandatory.");
}
if (empty($orderId)) {
throw new LockException("Can not unlock the order: no orderId was provided");
<?php
public function unlock($orderId, $userId)
{
$redis = $this->app['cache'];
if (empty($this->type) || empty($orderId) || !in_array($this->type, $this->availableType)) {
throw new LockException("Missing/Invalid parameters. Can't unlock for type: " . $this->type . " with id: " . $orderId);
}
<?php
if (empty($result)) {
throw new LockException("This order wasn't locked. Can't unlock");
}
<?php
if (!empty($result)) {
/* multiple lines, including the reason to be of the function */
} else {
throw new LockException("This order wasn't locked. Can't unlock");
}
@non-senses
non-senses / guard_clauses_02.php
Created January 30, 2020 19:07
guard_clauses_02.php
<?php
public function unlock($orderId, $userId)
{
$redis = $this->app['cache'];
if (empty($this->type) || empty($orderId) || !in_array($this->type, $this->availableType)) {
throw new LockException("Missing/Invalid parameters. Can't unlock for type: " . $this->type . " with id: " . $orderId);
}
@non-senses
non-senses / guard_clauses_01.php
Created January 30, 2020 19:00
Guard Clauses Snippets
<?php
/**
* Unlock a specific type of order. Unusually unlock after the confirm has been completed
*
* @param int $orderId Id of the object you unlock
* @return bool True on success
* @throws LockException
* @throws \Exception
*/
public function unlock($orderId, $userId)