This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Violates Import order nto gouped. | |
use Auth0\SDK\Auth0; | |
use Drupal\my_custom_module_1\Service\UserService; | |
use Drupal\my_custom_module_1\Entity\UserEntity; | |
use Drupal\my_custom_module_2\Service\MessageService; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
use Drupal\Core\Field\FieldItemList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// pseudo code | |
class VehicleFetchRestResource { | |
// GET /vehicle | |
public function get(Request $request) { | |
try { | |
// #1 Authentication layer | |
// Validate if the request is coming from trusted source. | |
Authenticate($request); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use JsonSchema\Validator; | |
use VehicleCreateSchema; | |
class VehicleCreateRestResource { | |
// POST handler | |
public function post() { | |
try { | |
$payload = (array)json_decode($this->request->getContent()); | |
$query = $this->request->query->all(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class VehicleCreateSchema { | |
// Schema file to validate POST request. | |
public function getCreateSchema() { | |
return (object) [ | |
"type" => "object", | |
"properties" => (object) [ | |
"name" => (object) [ | |
"type" => "string", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class VehicleCreateRestResource { | |
// POST handler | |
public function post() { | |
try { | |
$payload = (array)json_decode($this->request->getContent()); | |
$query = $this->request->query->all(); | |
// Vehicle Validator pseudo code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class VehicleCreateRestResource { | |
// POST handler | |
public function post() { | |
try { | |
$payload = []json_decode(\Drupal::request()->getContent()); | |
// Check if vehicle name is not empty. | |
if (empty($payload['name'])) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\node\Entity\Node; | |
/** | |
* Implements hook_update_N(). | |
* Patch Content of Type article. | |
*/ | |
function xyz_update_9001(&$sandbox) { | |
// Get count only if $sandbox['max'] is not set i.e the first time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class showing member function defined in ascending order. | |
*/ | |
class OrdereClassMethods { | |
public function a() {} | |
public function aa() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$food = 'cake'; | |
$return_value = match ($food) { | |
'apple' => 'This food is an apple', | |
'bar' => 'This food is a bar', | |
'cake' => 'This food is a cake', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\my_custom_module_1\Service\UserService; | |
use Drupal\my_custom_module_1\Entity\UserEntity; | |
use Drupal\my_custom_module_2\Service\MessageService; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
use Drupal\Core\Field\FieldItemList; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
use Symfony\Component\HttpFoundation\Request; |