Skip to content

Instantly share code, notes, and snippets.

@xmsi
Last active April 22, 2025 13:08
Show Gist options
  • Save xmsi/28ac597035f81354a7a7ac9f29ab83bb to your computer and use it in GitHub Desktop.
Save xmsi/28ac597035f81354a7a7ac9f29ab83bb to your computer and use it in GitHub Desktop.
Code sheat

Null Coalescing (??) vs Ternary (?:) operators

  • Null coalescing - check for null and performs next (?? ??=)
  • Ternary - check for false and performs next (?:)

Oneline if

if (is_string($hashesForCherryPick)) $hashesForCherryPick = explode(" ", $hashesForCherryPick);

Testing

Functional and Unit testing

  • Functional tests only in and out. Your soft becomes black-box, it kind of user behavior simulation
  • Unit tests inside of classes, how they were designed. Test component in an isolated way.

Stubs and Mocks

  • Stubs are fake objects, thatreturns something that you expect (API response, data)
  • Mocks are more advanced, they test behavior of a method (how much method was called, with what arguments, in what order)

Functions

Arguments vs Parameters

  • Parameters: Parameters are the variables listed inside the parentheses in a function's definition. They act as placeholders for the values that will be passed into the function when it's called. Think of them as the function's "input specifications."
  • Arguments: Arguments are the actual values that are passed to a function when it's called. They are the real data that the function will use during its execution. Think of them as the function's "actual inputs."
<?php

function add($num1, $num2) { // $num1 and $num2 are parameters
    return $num1 + $num2;
}

$result = add(5, 3); // 5 and 3 are arguments

echo $result; // Output: 8

Exceptions

Custom Exception

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment