Categories
BEST PHP CODE PHP PHPUnit

Useful catch (\Throwable $e)

catch (\Throwable $e) turned out to be very useful while coding in PHP.

When Exception were caught in specific instances, catch throwable would catch anything that would impede the code to run

Example below in a phpUnit scenario :

        try {
            $r = $this->checkKeys($data);
        } catch (\Throwable $e) {
            $this->assertEquals($e->getCode(), 404);
        }
Categories
Programming

Model and Reward Vulnerability on Your Team

Today’s Tip 
Model and Reward Vulnerability on Your Team
For a team to innovate, people must be willing to disagree, dissent, and challenge the status quo. As a leader, it’s your job to set the conditions for this kind of intellectual bravery. First, check yourself: Make sure you reward vulnerability, rather than punish it, and be mindful of the signals you’re sending, implicitly or explicitly, that discourage disagreement or outside-the-box thinking. Next, encourage your team members to think beyond their role and function. You can also specifically assign someone on your team to play the role of devil’s advocate — their job is to challenge a course of action or find flaws in a proposed decision. Make sure you rotate that role so you can get a variety of perspectives. Whenever you reject a suggestion, express gratitude for the idea and explain your reasoning. Finally, model vulnerability by sharing your mistakes, asking questions, and admitting what you don’t know. Laying the groundwork for open and honest discussions could help your team come up with your company’s next great idea.
This tip is adapted from “To Foster Innovation, Cultivate a Culture of Intellectual Bravery,” by Timothy R. Clark
Categories
Apache

APACHE CORS ISSUE FIXED

Errors

No 'Access-Control-Allow-Origin' header
access control check: The 'Access-Control-Allow-Origin' header contains multiple values
No 'Access-Control-Allow-Origin' header is present on the requested resource"

Solution

SetEnvIf Origin "^http(s)?://(.+.)?(4over.com|4over.com)$" origin_is=$0
Header set Access-Control-Allow-Origin %{origin_is}e env=origin_is
Header set Access-Control-Allow-Credentials "true"
Header always set Access-Control-Allow-Headers "Authorization"
Header always set Access-Control-Allow-Methods "GET"
Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
Header always set Access-Control-Max-Age "600"
Categories
Technical

+10,000 Downloads QuickLogs – Log Parser ! Yoohooo !

Demo : quicklogs.raleche.com

quicklogs

Useful if you are working from scratch on some projects and you find yourself without a quick interface to review the error logs produced. This package yana/dr comes with a quick authentication system called QuickAuth.

In 3 steps :

#1 – Install composer Package

composer require yana/dr

#2 – Update configuration file to read the log from [Yana/Logs/conf.php]

'error_log_path' => '/var/log/php-fpm/www-error.log',

#3 – Create the path/directory to visualize your logs and copy the following files

/public/log

Download here : https://packagist.org/packages/yana/dr

Quick Auth

David Raleche QuickAuth
David Raleche QuickAuth
david raleche quicklogs
david raleche quicklogs
quickAuth by David Raleche
quickAuth by David Raleche
Categories
PHP

Developer Manifesto by David Raleche

4 Principles are guiding this methodology


- Readability
- Quality Assurance
- Logic
- Reusable code

 Readability


PSR-2 code styling
Function no longer than 50 lines
PHP doc Block
TypeHint your functions

More information:

For better code readability we suggest PSR-2 code styling to be applied. We consider a function bigger than 25 lines is not an efficient function. For engaging this methodology we recommend 50 lines maximum per function. DocBloc are essentials. Swagger in a case of API writing is essential to be present.
A developer should be able to explain his work easily and quickly and should use materials to do so

Quality Insurance


No PHP error message
No PHP Warning messages
No PHP Notices
No hardcore credentials
Unit Testing
Details:

When executing the code we expect the quality assurance team to verify that no PHP errors, warnings, notices are produced. We also expect the QA team to go throughout the code to verify that no hardcore credentials are present within the code. Unit Test writing should be edited by QA team preferably

Logic


DRY (do not repeat yourself)
KISS (Keep it Stupid Simple)
SOLID principles

 Reusable Code


Use PHP throw exception
Use Object oriented techniques
Use static function

Use PHP throw exception
Use Object oriented techniques
Use static function

Add the following your PHP too get rid of PHP notices, warnings

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


Want to know more about my work around the LAMP stack world and other specialties? Sign up for our email brief for hand-picked articles, news, and more.

Subscribe

* indicates required

Categories
Technical

High 5 Games – Innovation

I had fun innovating directly with the facebook team at Menlo Park ! These many travels between high5games office located at the time in the world trade center 59th floor in New York and Facebook headquarter in Menlo Park were not lost ! Many years later our work still speaks volume ! Customer Experience was paramount in our unstoppable success !

Facebook API

Facebook Api, Facebook Payment, Facebook Authentication

Categories
Technical

Amazon Principles

— This is great for other companies to be inspired —

Leadership Principles

We use our Leadership Principles every day, whether we’re discussing ideas for new projects or deciding on the best approach to solving a problem. It is just one of the things that makes Amazon peculiar.

Customer Obsession

Leaders start with the customer and work backwards. They work vigorously to earn and keep customer trust. Although leaders pay attention to competitors, they obsess over customers.

Ownership

Leaders are owners. They think long term and don’t sacrifice long-term value for short-term results. They act on behalf of the entire company, beyond just their own team. They never say “that’s not my job.”

Invent and Simplify

Leaders expect and require innovation and invention from their teams and always find ways to simplify. They are externally aware, look for new ideas from everywhere, and are not limited by “not invented here.” As we do new things, we accept that we may be misunderstood for long periods of time.

Are Right, A Lot

Leaders are right a lot. They have strong judgment and good instincts. They seek diverse perspectives and work to disconfirm their beliefs.

Learn and Be Curious

Leaders are never done learning and always seek to improve themselves. They are curious about new possibilities and act to explore them.

Hire and Develop the Best

Leaders raise the performance bar with every hire and promotion. They recognize exceptional talent, and willingly move them throughout the organization. Leaders develop leaders and take seriously their role in coaching others. We work on behalf of our people to invent mechanisms for development like Career Choice.

Insist on the Highest Standards

Leaders have relentlessly high standards — many people may think these standards are unreasonably high. Leaders are continually raising the bar and drive their teams to deliver high quality products, services, and processes. Leaders ensure that defects do not get sent down the line and that problems are fixed so they stay fixed.

Think Big

Thinking small is a self-fulfilling prophecy. Leaders create and communicate a bold direction that inspires results. They think differently and look around corners for ways to serve customers.

Bias for Action

Speed matters in business. Many decisions and actions are reversible and do not need extensive study. We value calculated risk taking. 

Frugality

Accomplish more with less. Constraints breed resourcefulness, self-sufficiency, and invention. There are no extra points for growing headcount, budget size, or fixed expense.

Earn Trust

Leaders listen attentively, speak candidly, and treat others respectfully. They are vocally self-critical, even when doing so is awkward or embarrassing. Leaders do not believe their or their team’s body odor smells of perfume. They benchmark themselves and their teams against the best.

Dive Deep

Leaders operate at all levels, stay connected to the details, audit frequently, and are skeptical when metrics and anecdote differ. No task is beneath them.

Have Backbone; Disagree and Commit

Leaders are obligated to respectfully challenge decisions when they disagree, even when doing so is uncomfortable or exhausting. Leaders have conviction and are tenacious. They do not compromise for the sake of social cohesion. Once a decision is determined, they commit wholly.

Deliver Results

Leaders focus on the key inputs for their business and deliver them with the right quality and in a timely fashion. Despite setbacks, they rise to the occasion and never settle.

Categories
Book Study Recommendation Books

What’s New in PHP 8 ?

Union types

public function foo(Foo|Bar $input): int|float;

The nullsafe operator

$dateAsString = $startDate ? $startDate->asDateTimeString() : null;

$dateAsString = $booking->getStartDate()?->asDateTimeString();

New mixed type

function bar(): ?mixed {}

Throw expression

$triggerError = fn () => throw new MyError();

$foo = $bar[‘offset’] ?? throw new OffsetDoesNotExist(‘offset’);

READ -> https://stitcher.io/blog/new-in-php-8

Categories
Book Study Recommendation Books

Amazing Article ! Why I quit my job !

Amazing article wrote by https://twitter.com/brendt_gd

https://stitcher.io/blog/dont-get-stuck

Categories
API

What HTTP status response code should I use if the request is missing a required parameter?

The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.

https://stackoverflow.com/questions/3050518/what-http-status-response-code-should-i-use-if-the-request-is-missing-a-required