PHP code example of bbprojectnet / unit-helpers

1. Go to this page and download the library: Download bbprojectnet/unit-helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bbprojectnet / unit-helpers example snippets


// Before
$query->where('size', '>=', 209715200)->get();

// After
$query->where('size', '>=', Size::mb(200))->get();

// Before
$config = [
	'expiration' => 4680, // 3 days and 6 hours in minutes
];

// After
$config = [
	'expiration' => Time::of(days: 3, hours: 6, 'minutes'),
	// or
	'expiration' => Time::of(days: 3.25, 'minutes'),
	// or
	'expiration' => Time::days(3.25, 'minutes'),
];

// Before
class Job
{
	protected int $timeout = 10800;
}

// After
class Job
{
	protected int $timeout = Time::HOUR * 3;
}

$timeout = Time::hours(4);

$timeout = Time::hours(4, 'minutes');

$timeout = Time::of(days: 2);

$timeout = Time::of(days: 2, hours: 10);

$timeout = Time::of(days: 2, hours: 10, as: 'minutes');

$timeout = Time::of(days: 2.4, hours: -2, minutes: 0.5, as: 'minutes');

protected int $timeout = Time::HOUR * 3;