by
RicCastelhano
// BAD
echo "<a href=\"link\" title=\"some title\">Link to somewhere</a>";
// GOOD
echo '<a href="link" title="some title">Link to somewhere</a>';
// BAD
$my_array = array(
'first' => 1,
'second' => 2,
'third' => 3
);
// GOOD
$my_array = array(
'first' => 1,
'second' => 2,
'third' => 3,
);
// BAD
$my_array=array(1,2,3,4);
$my_var=10;
// GOOD
$my_array = array( 1, 2, 3, 4 );
$my_var = 10;
http://www.php-fig.org/
https://make.wordpress.org/core/handbook/best-practices/coding-standards/
https://github.com/airbnb/javascript
https://github.com/log-oscon/Standards
/**
* Get a post's permalink, then run it through special filters and trigger
* the 'special_action' action hook.
*
* @param int $post_id The post ID being linked to.
* @return str|bool The permalink or a boolean false if $post_id does not exist.
*/
function my_permalink_function( $post_id ) {
$permalink = get_permalink( absint( $post_id ) );
$permalink = apply_filters( 'special_filter', $permalink );
do_action( 'special_action', $permalink );
return $permalink;
}
public function test_my_permalink() {
WP_Mock::userFunction( 'get_permalink', array(
'args' => 42,
'times' => 1,
'return' => 'http://example.com/foo'
) );
WP_Mock::passthruFunction( 'absint', array( 'times' => 1 ) );
WP_Mock::onFilter( 'special_filter' )
->with( 'http://example.com/foo' )
->reply( 'https://example.com/bar' );
WP_Mock::expectAction( 'special_action', 'https://example.com/bar' );
$result = my_permalink_function( 42 );
$this->assertEquals( 'https://example.com/bar', $result );
}
http://phpunit.de/
https://github.com/10up/wp_mock
https://codeception.com/
Erich Fromm
(1900 - 1980)
by
RicCastelhano