Skip to main content

Posts

Showing posts from 2019

PHP Code Review Guidelines

General  The code works  The code is easy to understand  Follows coding conventions  Names are simple and if possible short  Names are spelt correctly  Names contain units where applicable  There are no usages of magic numbers  No hard coded constants that could possibly change in the future  All variables are in the smallest scope possible  There is no commented out code  There is no dead code (inaccessible at Runtime)  No code that can be replaced with library functions  Variables are not accidentally used with null values  Variables are immutable where possible  Code is not repeated or duplicated  There is an else block for every if clause even if it is empty  No complex/long boolean expressions  No negatively named boolean variables  No empty blocks of code  Ideal data structures are used  Constructors do not accept null/none values  Catch clause...

Week dates between two dates

To list week's start date & end date between given two dates. It also includes number of dates in every set. It allows you to list only those weeks having total seven days. Here the starting day of the week is Monday & the end day of the week is Sunday. /* * Returns array of week's start & end dates with number of days between those. * * @param string $start_date * @param string $end_date * @param boolean $only_full_week * * @return array */ function getWeekDates($start_date, $end_date, $only_full_week = false) { $stime = strtotime($start_date); $etime = strtotime($end_date); $weeks = array(); $i = 0; $j = 1; while ($stime <= $etime) { if ($i == 0 && $j == 1) { $weeks[$i]['start_date'] = date('Y-m-d', $stime); $weeks[$i]['end_date'] = date('Y-m-d', $stime); $weeks[$...