Skip to content

Commit 54cc6b6

Browse files
committed
Syntax highlighting in README.md
1 parent bff9c27 commit 54cc6b6

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,61 +20,66 @@ This class is similar to phpunit/php-timer, but not a fork, nor mimic its functi
2020

2121
## Installing
2222
The simplest way would be to install using [composer](https://getcomposer.org).
23-
23+
```bash
2424
composer require ayesh/php-timer
25+
```
2526

2627
If, for some reason you can't use Composer, or don't want to (oh come on!), you can integrate the class with your current `PSR-4` autoloader by mapping `Ayesh\PHP_TIMER` namespace to the repository's `src` folder.
2728

2829
## Usage
2930
It is pretty simple to use the timer, with all methods being static, and allowing only 4 methods.
3031

3132
#### Start timer
32-
33+
```php
34+
<?php
3335
use Ayesh\PHP_Timer\Timer;
3436
Timer::start();
37+
````
3538
This starts the timer (actually keeps the current time stored) with the key `default`. Throughout the library, if you do not provide a specific key, this default key is used.
3639

3740
Alternately, you can start the timer with a given key:
38-
41+
```php
3942
Timer::start('something');
43+
```
4044
Once you start the time with a given key, you can use the same key to refer to that particular timer.
4145
You can of course use PHP magic constants to make things easier:
42-
46+
```php
4347
Timer::start(__FUNCTION__);
48+
```
4449
Attempting to start the timer with a non-string key will throw a `\TypeError` exception.
4550
You can call the `start` method multiple times even if the timer has started. It will not reset the timer.
4651

4752
#### Read timer
4853
After starting the timer, you can read the elapsed time at any time. Reading the time will not stop the timer. You can read the timer, do some expensive calculations, and read again to get the cumulative time.
49-
54+
```php
5055
Timer::read(); // Default timer.
5156
Timer::read('default'); // Default timer.
5257
Timer::read('something'); // Timer started with key "something".
58+
```
5359
Attempting to read a timer that is not started will throw an `\LogicException` exception.
5460

5561
##### Formats
5662
You can pass a second argument to let this library make minimal processing for you:
57-
58-
Timer::read('something', Timer::FORMAT_PRECISE);
59-
// 0.10180473327637
60-
63+
```php
64+
Timer::read('something', Timer::FORMAT_PRECISE); // 0.10180473327637
65+
```
6166
See the formats section below for the formats supported.
6267
#### Stop timer
6368
You can stop the timer anytime as well. This makes the library store the stop time, and your further `Timer::read()` calls will always return the time it took between start and stop.
64-
69+
```php
6570
Timer::stop(); // Default timer.
6671
Timer::stop('something'); // Timer started with key "something"
67-
72+
```
6873
Attempting to stop a timer that is not started will throw an `\LogicException` exception.
6974

7075
#### Reset timer
7176
By default, starting the timer after stopping it will continue it from where it left off. For example, if you have 3 seconds on the timer when you stop it, and start it again, the total time will start from 3 seconds. You can explicitly reset the timer to make it start from 0.
7277
Resetting the timer will not make the timer start again. You need to explicitly start the timer again with a `Timer::start()` call.
73-
78+
```php
7479
Timer::reset(); // Default timer.
7580
Timer::reset('something');
7681
Timer::resetAll(); // Resets all timers.
77-
82+
```
7883
## Formats
7984
Currently, the following formats are provided:
8085

@@ -85,16 +90,18 @@ Currently, the following formats are provided:
8590
## Examples
8691

8792
#### Calculate the timer one-off:
88-
93+
```php
94+
<?php
8995
use Ayesh\PHP_Timer\Timer;
9096

9197
Timer::start();
9298
// do your processing here.
9399
$time = Timer::read('default', Timer::FORMAT_SECONDS);
94100
echo "Script took {$time} second(s)";
95-
101+
````
96102
#### Stop watch functionality, with stop-and-go timer calculated separately.
97-
103+
```php
104+
<?php
98105
use Ayesh\PHP_Timer\Timer;
99106

100107
Timer::start('full');
@@ -112,7 +119,7 @@ Currently, the following formats are provided:
112119
echo Timer::read('full', Timer::FORMAT_SECONDS); // 4 seconds.
113120
echo "<br />";
114121
echo Timer::read('laps', Timer::FORMAT_SECONDS); // 2 seconds (1 + 1)
115-
122+
````
116123
## Development and tests
117124
All issues are PRs are welcome. Travis CI and PHPUnit tests are included. If you are adding new features, please make sure to add the test coverage.
118125

src/Timer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Class Timer
88
*
9-
* Helper class to measure the execusion time between two points in a single
9+
* Helper class to measure the execution time between two points in a single
1010
* request.
1111
*
1212
* @package Ayesh\PHP_Timer
@@ -76,7 +76,7 @@ public static function resetAll() {
7676
}
7777

7878
/**
79-
* Pocesses the internal timer state to return the time elapsed.
79+
* Processes the internal timer state to return the time elapsed.
8080
* @param $value
8181
* @param $format
8282
* @return mixed
@@ -135,7 +135,10 @@ public static function read(string $key = 'default', $format = self::FORMAT_MILL
135135

136136
/**
137137
* Stops the timer with the given key. Default key is "default"
138+
*
138139
* @param string $key
140+
*
141+
* @throws \LogicException If the attempted timer has not started already.
139142
*/
140143
public static function stop($key = 'default') {
141144
if (isset(self::$timers[$key])) {

tests/TimerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testMultipleStartsQueued() {
7777
$this->assertGreaterThan($timer_1 + $timer_2, $timer_3);
7878
}
7979

80-
public function testMultpleStartCallsQueued_2() {
80+
public function testMultipleStartCallsQueued_2() {
8181
$key = 'foo';
8282
Timer::start($key);
8383
$this->assertLessThan(500, Timer::read($key));

0 commit comments

Comments
 (0)