Slide 1

Slide 1 text

Code Deodorant Prevention > Cure

Slide 2

Slide 2 text

I’m Tom J Nowell Code For The People

Slide 3

Slide 3 text

Code Smells

Slide 4

Slide 4 text

Home page templates The Template Hierarchy provides: ● home.php ● front-page.php

Slide 5

Slide 5 text

Indenting

Widgetized area 1

This panel is active and ready for you to add some widgets via the WP Admin

Widgetized area 2

This panel is active and ready for you to add some widgets via the WP Admin

Slide 6

Slide 6 text

Throwing away the main query query_posts(‘...’);

Slide 7

Slide 7 text

Warnings and @ PHP Warning: strip_tags() expects parameter 1 to be string, array given in … $str = @strip_tags(‘example’);

Slide 8

Slide 8 text

eval & create_function add_action( ‘the_content’, create_function(‘return “hello”; ’) );

Slide 9

Slide 9 text

Anonymous Objects class Davina_Plugin { function __construct() { add_filter( 'the_content', array( $this, 'swear' ), -1 ); } function swear( $content ) { return "Hello big brother house, you are live on channel 4, do not say sh*t f*ck or b*gger"; } } new Davina_Plugin();

Slide 10

Slide 10 text

Prevention by Design

Slide 11

Slide 11 text

pre_get_posts function exclude_cat( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-1,-1347' ); } } add_action( 'pre_get_posts', 'exclude_cat' );

Slide 12

Slide 12 text

Dependency Injection Constructor Injection $obj = new test( $dependencies ); Method injection $obj->setThing( $thing );

Slide 13

Slide 13 text

Demeters Law $object->getChild()->doThing();

Slide 14

Slide 14 text

No global variables

Slide 15

Slide 15 text

Prevention by Tools and Numbers

Slide 16

Slide 16 text

PHP Syntax checking If your editor doesn’t do it for you, something is very wrong...

Slide 17

Slide 17 text

PHP Code Sniffer

Slide 18

Slide 18 text

PHP Metrics

Slide 19

Slide 19 text

PHPLOC

Slide 20

Slide 20 text

PHP Mess Detector

Slide 21

Slide 21 text

NPath & Cyclomatic Complexity

Slide 22

Slide 22 text

So How Does WordPress Fair?

Slide 23

Slide 23 text

PHPMD phpmd wordpress text codesize, controversial, design, unusedcode > core.txt

Slide 24

Slide 24 text

wp_insert_post 661,197,634,560,000,000,000 6.6x10^19

Slide 25

Slide 25 text

redirect_canonical 1,620,651,275,242,427,205,550,080 1.62x10^24

Slide 26

Slide 26 text

WP_Query::get_posts 1,435,733,941,397,422,709,124,940,625,188, 500,371,668,992,000,000 1.43x10^48

Slide 27

Slide 27 text

Calculations 1 unit test = 1.5kb 1 Samsung 1TB drive = 0.4kg 80 Undecillion kg or 8x1037kg or~4 solar masses

Slide 28

Slide 28 text

Beta Sagittae

Slide 29

Slide 29 text

WP_Query::get_posts WP 4.0 58,430,498,159,114,868,447,575,084,102,205, 776,212,823,109,373,305,815,040,000 5.8x10^58

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

The Sombrero Galaxy

Slide 32

Slide 32 text

Large Megallenic Cloud

Slide 33

Slide 33 text

162,789,208,987 Solar Masses 1x10^9 - Sombrero Galaxy 1x10^10 - Large Megallenic Cloud dwarf galaxy 1.6x10^11 - WP_Query::get_posts unit test ( 2TB Samsung HD's ) 1.5×10^12 - Milky Way

Slide 34

Slide 34 text

Questions? @tarendai tomjn.com