SlideShare a Scribd company logo
1 of 44
Place your screenshot here
Essential
Tools for
Modern PHP
Alex Weissman
GIT
PSR
Composer NODE.JS
PHP
UNIT
PHP
DOC
MARKDOWN
Fred Brooks, The Mythical Man-Month
We learn how to
make this in school
(or at home)
But this is what
we're building in
the "real world"
Git
Version control system,
the basis for Github.
Stores snapshots,
enhances collaboration.
Composer
A dependency manager
for PHP.
Node.js
An open-source cross-
platform runtime
environment, helps with
asset management and
deployment. Node Package
Manager, npm, is its
dependency manager.
PSR
Coding standards for
PHP that include
formatting, syntax, best
practices and
interoperability.
PHP Unit
Essential tool for creating
and running automated
tests.
PHP Doc
Standards for low-level
documentation
(comments) in your code
base.
Overview
Essential
Tools
Markdown
A language for formatting
plain text. Makes
communication easier.
What is the main job of a
software developer?
The ratio of time spent reading versus writing is
well over 10 to 1. We are constantly reading old
code as part of the effort to write new code.
...[Therefore,] making it easy to read makes it
easier to write.
― Robert C. Martin, Clean Code: A Handbook of
Agile Software Craftsmanship
MARKDOWN, PHPDOC,
AND CODING STYLE
01
MARKDOWN
● The format for writing readable content (especially code) on the web
● Alternative to allowing people to enter HTML, which:
○ Is more verbose and takes longer to write;
○ Requires special handling to prevent XSS attacks
MARKDOWN
MARKDOWN
https://daringfireball.net/projects/markdown/
PHPDOC
● Document each file, class, member variable, and method with a DocBlock
● DocBlocks contain both free text descriptions and structured metadata (tags)
● DocBlocks can be automatically parsed by:
○ Text editors and IDEs for type-hinting and code completion;
○ Standalone tools to generate API documentation
/**
* A BelongsToMany relationship that supports ternary (three-way) pivot relationships.
*
* @author Alex Weissman (https://alexanderweissman.com)
* @link https://github.com/laravel/framework/
*/
class BelongsToTernary extends BelongsToMany
{
…
}
PHPDOC
https://docs.phpdoc.org/
CODING STYLE
PHP Standards Recommendations (PSRs): PSR-1 and PSR-2
CODING STYLE
usrefrostieng is a web framework for php
but other web framework offers a
compleate toolbox of pogram modules for
build app.its a fully-functioning user
managment ap unlike other php famework
right out of the box and full extandable
so that you can easly create the custom
feature userfroasting design hellp new and return
devlopers up to speed at modern php so youll be
comfortably intoduce to COMPOSER and PSR for
better structure ur code and easy manage when you'll
learn use node and Bower to cleanly manage client-
side packages (JAVASCRIPT and CSS)
UserFrosting is a web framework for PHP. Like other web
frameworks, it offers a complete toolbox of programmatic
components for building your application.
Unlike other PHP frameworks, it's a fully-functioning user
management application, right out of the box. And, it's fully
extendable so that you can easily create the custom features
you need.
UserFrosting is designed to bring new and returning
developers up to speed with the modern PHP community.
You'll be comfortably introduced to Composer (the
dependency manager), object-oriented design patterns, and
the PHP Standards Recommendations (PSR), making your
code better structured and easier to manage.
What's more, you'll learn how to use Node.js and Bower to
cleanly manage client-side packages (Javascript and CSS).
Transform yourself from a code monkey into a software
engineer.
CODING STYLE
class loggedInUser {
public $email = NULL;
public $hash_pw = NULL;
public $user_id = NULL;
public $csrf_token = NULL;
// Simple function to update the last sign in of a user
public function updateLastSignIn() {
updateUserLastSignIn($this->user_id);
}
// Return the timestamp when this user's account was registered
public function signupTimeStamp(){
return fetchUserField($this->user_id, 'sign_up_stamp');
}
//csrf tokens
public function csrf_token($regen = false)
{
if($regen === true) {
//*make sure token is set, if so unset*//
if(isset($_SESSION["__csrf_token"])) {
unset($_SESSION["__csrf_token"]);
}
if (function_exists('openssl_random_pseudo_bytes')) {
$rand_num =
openssl_random_pseudo_bytes(16);//pull 16 bytes from /dev/random
}else{
CODING STYLE
namespace AppModel;
class LoggedInUser
{
public $id = NULL;
public $email = NULL;
public $password = NULL;
public $csrfToken = NULL;
/**
* Update the last sign in time of a user
*
* @return AppModelLoggedInUser
*/
public function updateLastSignIn()
{
$this->updateField('last_sign_in');
return $this;
}
/**
* Return the timestamp for when this user's account was registered
*
* @return string
*/
public function signupTimeStamp()
{
return $this->fetchField('sign_up_stamp');
}
}
PSR-1 and PSR-2
● Don’t use ?>
● 4 spaces for indentation
○ DON’T use tabs
○ DO configure your text editor to write 4 spaces when you press tab
● One statement;
● Per line;
● Control structures: opening brace on same line
● This code snippet encompasses a lot of the other formatting rules:
if ($a === $b) {
bar();
} elseif ($a > $b) {
$foo->bar($arg1);
} else {
BazClass::bar($arg2, $arg3);
}
<?php
/**
* Owl Fancy
*
* @link https://owlfancy.com
* @license All rights reserved
*/
namespace AppModels;
use AppMailMailer;
class Member
{
/**
* Email member with reminder to renew subscription.
*
* @param AppMailContact $senderInfo
* @param string $params
* @return string
*/
public function sendSubscriptionReminder($senderInfo, $params)
{
$message = new Mailer($senderInfo, $this->email);
return $message->render('bill-reminder.html.twig', $params);
}
...
}
Object-oriented programming
• Namespaces!
• Stricter naming conventions for
classes, methods
• One class per file!
• Separation of concerns. Avoid
side effects - A file should either
define symbols OR perform
logic/render content
PSR-1 and PSR-2
PSR’s don’t have rules for
everything, but you should
Be consistent, even if PSR's do not provide a specific requirement!
• Variables - choose a style like camelCase;
• Functions - camelCase;
• Array keys - snake_case;
• Double vs single quotes - single quotes when double aren’t necessary
• Naming conventions – create vs createUser vs userCreate
GIT
02
WHAT IS VERSION CONTROL?
Version control systems are a category of software
tools that help a software team manage changes
to source code over time.
- Atlassian, Git Tutorial
Life before
version control
● What has been changed from one version to
the next?
● Who made those changes, and why?
● How can I integrate changes that have been
made by multiple developers in a non-blocking
way?
● Finding specific changes and stepping back to
previous states?
● I'd like to do these things efficiently and
automatically.
A tool that solves...
Life after
version control
• I know who did what and when.
• I can easily see what has changed.
• Commit messages summarize
changes.
• Collaboration with team members
and the open source community.
• I can use it for deployment.
How git works
The working tree is my code, as it stands right
now.
A change is adding, modifying, or deleting a line
of code in my working tree.
A commit is a set of changes made by a
specific person at a specific point in time.
The repository is the current working tree
together with its commit history and various
references to specific commits.
This is all happening locally, on your machine.
ANATOMY OF A GIT REPOSITORY
alexw @ 2017-01-01 03:05:49
Fix directory traversal vulnerability
3 lines added, 4 changed, 2 removed
alexw @ 2017-01-01 22:11:17
Fix directory traversal vulnerability
for real this time
7 lines changed
sarah @ 2017-01-04 11:17:10
Improve Alex's terrible CSS
4 lines changed, 3 removed
HEAD
alexw @ 2017-01-01 03:05:49
Fix directory traversal vulnerability
3 lines added, 4 changed, 2 removed
alexw @ 2017-01-01 22:11:17
Fix directory traversal vulnerability
for real this time
7 lines changed
sarah @ 2017-01-04 11:17:10
Improve Alex's terrible CSS
4 lines changed, 3 removed
HEAD
site/
├── config/
└── default.php
├── src/
└── composer.json
alexw @ 2017-01-05 23:18:01
Turn off debugging in config
2 lines changed, 1 removed
site/
├── config/
└── default.php
├── src/
└── composer.json
commit
stage
working tree commit history
older commits
ANATOMY OF A GIT REPOSITORY
Remotes
● A remote refers to an authoritative version
of the project on a server.
● Github offers public remote repositories for
free.
● For private repos, use Bitbucket for free,
run your own git server, or get a paid
Github account.
● git clone creates a new user’s local
copy of the project, with the full history
● git push adds a user’s local commits to
the repository
● git pull adds other team member’s
changes to a user’s local copy
● Git uses various strategies to deal with
complex changes. These are fetch and
merge strategies, and learn about these in
an advanced course. Merge conflicts can
be manually resolved where needed.
Branches
● git branch creates an alternative
timeline for experimental features,
bugfixes, and divergent ideas.
● Branches can be merged or discarded as
needed.
● git checkout allows you to switch
between branches
GIT
COMPOSER
03
COMPOSER
● The dependency (package) management tool for PHP since 2012
● Downloads and installs packages from packagist.org
● Automatically resolves dependency graphs
● Designed in conjunction with PSR-4 (autoloading)
<?php
error_reporting (E_ALL ^ E_WARNING);
require('./class_definitions.inc');
require('./user_profiles.inc');
require('./file_submission.inc');
require('configurator_object.inc');
$configurators = array();
require('load_objects.inc');
unset($configurators);
session_start();
<?php
require_once __DIR__ . '/../vendor/autoload.php';
COMPOSER
{
"name": "userfrosting/userfrosting",
"require": {
"pimple/pimple": "~3.1.0",
"slim/slim": ”^3.0"
},
"autoload": {
"psr-4": {
"UserFrostingSprinkleCore": "src/"
}
}
}
composer.json
$ composer install
$ composer update
COMPOSER
userfrosting/userfrosting 4.1
pimple/pimple ~3.1.0
pimple/pimple 3.*
slimphp/slim ^3.0
psr/container 1.0
COMPOSER
userfrosting/userfrosting 4.1
pimple/pimple ~3.1.0
pimple/pimple 3.*
slimphp/slim ^3.0
psr/container 1.0
COMPOSER
vendor/
├── pimple/pimple 3.1.2
├── slimphp/slim 3.9
└── psr/container 1.0
hey man you see
that package over
there
he doesn’t use
semantic versioning
COMPOSER
AUTOMATED TESTING
WITH PHPUNIT
04
AUTOMATED TESTING
• Prevent regressions!
• More confidence when
making changes
• Built-in specifications
AUTOMATED TESTING
Functional tests
• Test overall behavior and I/O
• Fairly easy to write, even for
existing code
public function testBelongsToMany()
{
$worker = EloquentTestWorker::first();
$worker->jobs()->attach([1,2]);
$this->assertArrayEqual([
[
'id' => 1,
'label' => 'forager',
'pivot' => [
'worker_id' => 1,
'job_id' => 1
]
],
…
], $worker->jobs->toArray());
}
AUTOMATED TESTING
Unit tests
• Test individual methods
• Test both what your methods do
and how they do it
• Harder to write, requires careful
design (design for testability,
inversion of control)
• Often written before the code itself
as a specification (test-driven
development)
• Mockery
public function testSyncMethod($list)
{
$relation = $this->getRelation();
// Simulate determination of related key from builder
$relation->getRelated()->shouldReceive('getKeyName')->once()-
>andReturn('id');
// Simulate fetching of current relationships (1,2,3)
$query = m::mock('stdClass');
$relation->shouldReceive('newQuery')->once()->andReturn($query);
$query->shouldReceive('pluck')->once()->with('id')->andReturn(new
BaseCollection([1, 2, 3]));
// withoutGlobalScopes will get called exactly 3 times
$relation->getRelated()->shouldReceive('withoutGlobalScopes')-
>times(3)->andReturn($query);
// Test deletions of items removed from relationship (1)
$query->shouldReceive('whereIn')->once()->with('id', [1])-
>andReturn($query);
$query->shouldReceive('delete')->once()->andReturn($query);
…
// Check result
$this->assertEquals(['created' => ['x'], 'deleted' => [1],
'updated' => [2,3]], $relation->sync($list));
}
BUILDING AND
DEPLOYMENT
05
BUILDING AND DEPLOYMENT
THANK YOU!

More Related Content

What's hot

What's hot (20)

ある工場のRedmine画面カスタム【View customize plugin 活用例】
ある工場のRedmine画面カスタム【View customize plugin 活用例】ある工場のRedmine画面カスタム【View customize plugin 活用例】
ある工場のRedmine画面カスタム【View customize plugin 活用例】
 
Robo Recallで使われている 最新のVR開発テクニックをご紹介!
Robo Recallで使われている最新のVR開発テクニックをご紹介!Robo Recallで使われている最新のVR開発テクニックをご紹介!
Robo Recallで使われている 最新のVR開発テクニックをご紹介!
 
Redmine + Lychee導入のアンチパターン
Redmine + Lychee導入のアンチパターンRedmine + Lychee導入のアンチパターン
Redmine + Lychee導入のアンチパターン
 
CleanArchitecture 第4部 「コンポーネントの原則」
CleanArchitecture 第4部 「コンポーネントの原則」CleanArchitecture 第4部 「コンポーネントの原則」
CleanArchitecture 第4部 「コンポーネントの原則」
 
View customize1.2.0の紹介
View customize1.2.0の紹介View customize1.2.0の紹介
View customize1.2.0の紹介
 
Steamで同人ゲームをリリースする ~パブリッシャーになって検証してみた~
Steamで同人ゲームをリリースする ~パブリッシャーになって検証してみた~Steamで同人ゲームをリリースする ~パブリッシャーになって検証してみた~
Steamで同人ゲームをリリースする ~パブリッシャーになって検証してみた~
 
Redmineカスタムフィールド表示改善
Redmineカスタムフィールド表示改善Redmineカスタムフィールド表示改善
Redmineカスタムフィールド表示改善
 
[CEDEC2018] UE4で多数のキャラクターを生かすためのテクニック
[CEDEC2018] UE4で多数のキャラクターを生かすためのテクニック[CEDEC2018] UE4で多数のキャラクターを生かすためのテクニック
[CEDEC2018] UE4で多数のキャラクターを生かすためのテクニック
 
挫折しないRedmine
挫折しないRedmine挫折しないRedmine
挫折しないRedmine
 
講演1 redmineの簡易crmとしての活用事例r2
講演1 redmineの簡易crmとしての活用事例r2講演1 redmineの簡易crmとしての活用事例r2
講演1 redmineの簡易crmとしての活用事例r2
 
NAVER TECH CONCERT_FE2019_오늘부터 나도 FE 성능분석가
NAVER TECH CONCERT_FE2019_오늘부터 나도 FE 성능분석가NAVER TECH CONCERT_FE2019_오늘부터 나도 FE 성능분석가
NAVER TECH CONCERT_FE2019_오늘부터 나도 FE 성능분석가
 
View Customize Pluginで出来ること
View Customize Pluginで出来ることView Customize Pluginで出来ること
View Customize Pluginで出来ること
 
継続使用と新規追加したRedmine Plugin
継続使用と新規追加したRedmine Plugin継続使用と新規追加したRedmine Plugin
継続使用と新規追加したRedmine Plugin
 
VRモーキャプツール『VR Motion Recorder』の使い方
VRモーキャプツール『VR Motion Recorder』の使い方VRモーキャプツール『VR Motion Recorder』の使い方
VRモーキャプツール『VR Motion Recorder』の使い方
 
ある工場の Redmine 2022 〜ある工場の Redmine 5.0 バージョンアップ〜 ( Redmine of one plant 2022 ...
ある工場の Redmine 2022 〜ある工場の Redmine 5.0 バージョンアップ〜 (  Redmine of one plant 2022 ...ある工場の Redmine 2022 〜ある工場の Redmine 5.0 バージョンアップ〜 (  Redmine of one plant 2022 ...
ある工場の Redmine 2022 〜ある工場の Redmine 5.0 バージョンアップ〜 ( Redmine of one plant 2022 ...
 
大規模ゲーム開発における build 高速化と安定化
大規模ゲーム開発における build 高速化と安定化大規模ゲーム開発における build 高速化と安定化
大規模ゲーム開発における build 高速化と安定化
 
猫でも分かるUE4を使った VRコンテンツ開発 超入門編 2021
猫でも分かるUE4を使った VRコンテンツ開発 超入門編 2021猫でも分かるUE4を使った VRコンテンツ開発 超入門編 2021
猫でも分かるUE4を使った VRコンテンツ開発 超入門編 2021
 
【Unite Tokyo 2019】ゼロから始めるアラビア語レンダリング
【Unite Tokyo 2019】ゼロから始めるアラビア語レンダリング【Unite Tokyo 2019】ゼロから始めるアラビア語レンダリング
【Unite Tokyo 2019】ゼロから始めるアラビア語レンダリング
 
UnrealBuildTool勉強会まとめ
UnrealBuildTool勉強会まとめUnrealBuildTool勉強会まとめ
UnrealBuildTool勉強会まとめ
 
Git flow
Git flowGit flow
Git flow
 

Viewers also liked

Viewers also liked (9)

Hacking Laravel - Custom Relationships with Eloquent
Hacking Laravel - Custom Relationships with EloquentHacking Laravel - Custom Relationships with Eloquent
Hacking Laravel - Custom Relationships with Eloquent
 
Web Performance 2017: Myths and Truths (php[world] 2017)
Web Performance 2017: Myths and Truths (php[world] 2017)Web Performance 2017: Myths and Truths (php[world] 2017)
Web Performance 2017: Myths and Truths (php[world] 2017)
 
Developing applications for performance
Developing applications for performanceDeveloping applications for performance
Developing applications for performance
 
Inheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalInheritance: Vertical or Horizontal
Inheritance: Vertical or Horizontal
 
Leveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantageLeveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantage
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?
 

Similar to Essential Tools for Modern PHP

Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
Nicole Gomez
 

Similar to Essential Tools for Modern PHP (20)

Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
 
Jbossworld Presentation
Jbossworld PresentationJbossworld Presentation
Jbossworld Presentation
 
Php Dependency Management with Composer ZendCon 2017
Php Dependency Management with Composer ZendCon 2017Php Dependency Management with Composer ZendCon 2017
Php Dependency Management with Composer ZendCon 2017
 
An intro to git
An intro to gitAn intro to git
An intro to git
 
How to Build a Custom Plugin in Rundeck
How to Build a Custom Plugin in RundeckHow to Build a Custom Plugin in Rundeck
How to Build a Custom Plugin in Rundeck
 
The DevOps paradigm - the evolution of IT professionals and opensource toolkit
The DevOps paradigm - the evolution of IT professionals and opensource toolkitThe DevOps paradigm - the evolution of IT professionals and opensource toolkit
The DevOps paradigm - the evolution of IT professionals and opensource toolkit
 
The DevOps Paradigm
The DevOps ParadigmThe DevOps Paradigm
The DevOps Paradigm
 
Open event presentation.3 2
Open event presentation.3 2Open event presentation.3 2
Open event presentation.3 2
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Best practices tekx
Best practices tekxBest practices tekx
Best practices tekx
 
Gerrit linuxtag2011
Gerrit linuxtag2011Gerrit linuxtag2011
Gerrit linuxtag2011
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
 
AtoZ about TYPO3 v8 CMS
AtoZ about TYPO3 v8 CMSAtoZ about TYPO3 v8 CMS
AtoZ about TYPO3 v8 CMS
 
Rails Rookies Bootcamp - Blogger
Rails Rookies Bootcamp - BloggerRails Rookies Bootcamp - Blogger
Rails Rookies Bootcamp - Blogger
 
Managing software product versioning with Gitflow, VSTS and Atlassian SourceTree
Managing software product versioning with Gitflow, VSTS and Atlassian SourceTreeManaging software product versioning with Gitflow, VSTS and Atlassian SourceTree
Managing software product versioning with Gitflow, VSTS and Atlassian SourceTree
 
Going open source with small teams
Going open source with small teamsGoing open source with small teams
Going open source with small teams
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 

Recently uploaded

pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 

Recently uploaded (20)

pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 

Essential Tools for Modern PHP

  • 1. Place your screenshot here Essential Tools for Modern PHP Alex Weissman GIT PSR Composer NODE.JS PHP UNIT PHP DOC MARKDOWN
  • 2. Fred Brooks, The Mythical Man-Month We learn how to make this in school (or at home) But this is what we're building in the "real world"
  • 3. Git Version control system, the basis for Github. Stores snapshots, enhances collaboration. Composer A dependency manager for PHP. Node.js An open-source cross- platform runtime environment, helps with asset management and deployment. Node Package Manager, npm, is its dependency manager. PSR Coding standards for PHP that include formatting, syntax, best practices and interoperability. PHP Unit Essential tool for creating and running automated tests. PHP Doc Standards for low-level documentation (comments) in your code base. Overview Essential Tools Markdown A language for formatting plain text. Makes communication easier.
  • 4. What is the main job of a software developer?
  • 5. The ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. ...[Therefore,] making it easy to read makes it easier to write. ― Robert C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship
  • 7. MARKDOWN ● The format for writing readable content (especially code) on the web ● Alternative to allowing people to enter HTML, which: ○ Is more verbose and takes longer to write; ○ Requires special handling to prevent XSS attacks
  • 10. PHPDOC ● Document each file, class, member variable, and method with a DocBlock ● DocBlocks contain both free text descriptions and structured metadata (tags) ● DocBlocks can be automatically parsed by: ○ Text editors and IDEs for type-hinting and code completion; ○ Standalone tools to generate API documentation /** * A BelongsToMany relationship that supports ternary (three-way) pivot relationships. * * @author Alex Weissman (https://alexanderweissman.com) * @link https://github.com/laravel/framework/ */ class BelongsToTernary extends BelongsToMany { … }
  • 12. CODING STYLE PHP Standards Recommendations (PSRs): PSR-1 and PSR-2
  • 13. CODING STYLE usrefrostieng is a web framework for php but other web framework offers a compleate toolbox of pogram modules for build app.its a fully-functioning user managment ap unlike other php famework right out of the box and full extandable so that you can easly create the custom feature userfroasting design hellp new and return devlopers up to speed at modern php so youll be comfortably intoduce to COMPOSER and PSR for better structure ur code and easy manage when you'll learn use node and Bower to cleanly manage client- side packages (JAVASCRIPT and CSS) UserFrosting is a web framework for PHP. Like other web frameworks, it offers a complete toolbox of programmatic components for building your application. Unlike other PHP frameworks, it's a fully-functioning user management application, right out of the box. And, it's fully extendable so that you can easily create the custom features you need. UserFrosting is designed to bring new and returning developers up to speed with the modern PHP community. You'll be comfortably introduced to Composer (the dependency manager), object-oriented design patterns, and the PHP Standards Recommendations (PSR), making your code better structured and easier to manage. What's more, you'll learn how to use Node.js and Bower to cleanly manage client-side packages (Javascript and CSS). Transform yourself from a code monkey into a software engineer.
  • 14. CODING STYLE class loggedInUser { public $email = NULL; public $hash_pw = NULL; public $user_id = NULL; public $csrf_token = NULL; // Simple function to update the last sign in of a user public function updateLastSignIn() { updateUserLastSignIn($this->user_id); } // Return the timestamp when this user's account was registered public function signupTimeStamp(){ return fetchUserField($this->user_id, 'sign_up_stamp'); } //csrf tokens public function csrf_token($regen = false) { if($regen === true) { //*make sure token is set, if so unset*// if(isset($_SESSION["__csrf_token"])) { unset($_SESSION["__csrf_token"]); } if (function_exists('openssl_random_pseudo_bytes')) { $rand_num = openssl_random_pseudo_bytes(16);//pull 16 bytes from /dev/random }else{
  • 15. CODING STYLE namespace AppModel; class LoggedInUser { public $id = NULL; public $email = NULL; public $password = NULL; public $csrfToken = NULL; /** * Update the last sign in time of a user * * @return AppModelLoggedInUser */ public function updateLastSignIn() { $this->updateField('last_sign_in'); return $this; } /** * Return the timestamp for when this user's account was registered * * @return string */ public function signupTimeStamp() { return $this->fetchField('sign_up_stamp'); } }
  • 16. PSR-1 and PSR-2 ● Don’t use ?> ● 4 spaces for indentation ○ DON’T use tabs ○ DO configure your text editor to write 4 spaces when you press tab ● One statement; ● Per line; ● Control structures: opening brace on same line ● This code snippet encompasses a lot of the other formatting rules: if ($a === $b) { bar(); } elseif ($a > $b) { $foo->bar($arg1); } else { BazClass::bar($arg2, $arg3); }
  • 17. <?php /** * Owl Fancy * * @link https://owlfancy.com * @license All rights reserved */ namespace AppModels; use AppMailMailer; class Member { /** * Email member with reminder to renew subscription. * * @param AppMailContact $senderInfo * @param string $params * @return string */ public function sendSubscriptionReminder($senderInfo, $params) { $message = new Mailer($senderInfo, $this->email); return $message->render('bill-reminder.html.twig', $params); } ... } Object-oriented programming • Namespaces! • Stricter naming conventions for classes, methods • One class per file! • Separation of concerns. Avoid side effects - A file should either define symbols OR perform logic/render content PSR-1 and PSR-2
  • 18. PSR’s don’t have rules for everything, but you should Be consistent, even if PSR's do not provide a specific requirement! • Variables - choose a style like camelCase; • Functions - camelCase; • Array keys - snake_case; • Double vs single quotes - single quotes when double aren’t necessary • Naming conventions – create vs createUser vs userCreate
  • 20. WHAT IS VERSION CONTROL? Version control systems are a category of software tools that help a software team manage changes to source code over time. - Atlassian, Git Tutorial
  • 22. ● What has been changed from one version to the next? ● Who made those changes, and why? ● How can I integrate changes that have been made by multiple developers in a non-blocking way? ● Finding specific changes and stepping back to previous states? ● I'd like to do these things efficiently and automatically. A tool that solves...
  • 23. Life after version control • I know who did what and when. • I can easily see what has changed. • Commit messages summarize changes. • Collaboration with team members and the open source community. • I can use it for deployment.
  • 24. How git works The working tree is my code, as it stands right now. A change is adding, modifying, or deleting a line of code in my working tree. A commit is a set of changes made by a specific person at a specific point in time. The repository is the current working tree together with its commit history and various references to specific commits. This is all happening locally, on your machine.
  • 25. ANATOMY OF A GIT REPOSITORY alexw @ 2017-01-01 03:05:49 Fix directory traversal vulnerability 3 lines added, 4 changed, 2 removed alexw @ 2017-01-01 22:11:17 Fix directory traversal vulnerability for real this time 7 lines changed sarah @ 2017-01-04 11:17:10 Improve Alex's terrible CSS 4 lines changed, 3 removed HEAD
  • 26. alexw @ 2017-01-01 03:05:49 Fix directory traversal vulnerability 3 lines added, 4 changed, 2 removed alexw @ 2017-01-01 22:11:17 Fix directory traversal vulnerability for real this time 7 lines changed sarah @ 2017-01-04 11:17:10 Improve Alex's terrible CSS 4 lines changed, 3 removed HEAD site/ ├── config/ └── default.php ├── src/ └── composer.json alexw @ 2017-01-05 23:18:01 Turn off debugging in config 2 lines changed, 1 removed site/ ├── config/ └── default.php ├── src/ └── composer.json commit stage working tree commit history older commits ANATOMY OF A GIT REPOSITORY
  • 27. Remotes ● A remote refers to an authoritative version of the project on a server. ● Github offers public remote repositories for free. ● For private repos, use Bitbucket for free, run your own git server, or get a paid Github account. ● git clone creates a new user’s local copy of the project, with the full history ● git push adds a user’s local commits to the repository ● git pull adds other team member’s changes to a user’s local copy ● Git uses various strategies to deal with complex changes. These are fetch and merge strategies, and learn about these in an advanced course. Merge conflicts can be manually resolved where needed.
  • 28. Branches ● git branch creates an alternative timeline for experimental features, bugfixes, and divergent ideas. ● Branches can be merged or discarded as needed. ● git checkout allows you to switch between branches
  • 29. GIT
  • 31. COMPOSER ● The dependency (package) management tool for PHP since 2012 ● Downloads and installs packages from packagist.org ● Automatically resolves dependency graphs ● Designed in conjunction with PSR-4 (autoloading)
  • 32. <?php error_reporting (E_ALL ^ E_WARNING); require('./class_definitions.inc'); require('./user_profiles.inc'); require('./file_submission.inc'); require('configurator_object.inc'); $configurators = array(); require('load_objects.inc'); unset($configurators); session_start(); <?php require_once __DIR__ . '/../vendor/autoload.php';
  • 33. COMPOSER { "name": "userfrosting/userfrosting", "require": { "pimple/pimple": "~3.1.0", "slim/slim": ”^3.0" }, "autoload": { "psr-4": { "UserFrostingSprinkleCore": "src/" } } } composer.json $ composer install $ composer update
  • 36. COMPOSER vendor/ ├── pimple/pimple 3.1.2 ├── slimphp/slim 3.9 └── psr/container 1.0 hey man you see that package over there he doesn’t use semantic versioning
  • 39. AUTOMATED TESTING • Prevent regressions! • More confidence when making changes • Built-in specifications
  • 40. AUTOMATED TESTING Functional tests • Test overall behavior and I/O • Fairly easy to write, even for existing code public function testBelongsToMany() { $worker = EloquentTestWorker::first(); $worker->jobs()->attach([1,2]); $this->assertArrayEqual([ [ 'id' => 1, 'label' => 'forager', 'pivot' => [ 'worker_id' => 1, 'job_id' => 1 ] ], … ], $worker->jobs->toArray()); }
  • 41. AUTOMATED TESTING Unit tests • Test individual methods • Test both what your methods do and how they do it • Harder to write, requires careful design (design for testability, inversion of control) • Often written before the code itself as a specification (test-driven development) • Mockery public function testSyncMethod($list) { $relation = $this->getRelation(); // Simulate determination of related key from builder $relation->getRelated()->shouldReceive('getKeyName')->once()- >andReturn('id'); // Simulate fetching of current relationships (1,2,3) $query = m::mock('stdClass'); $relation->shouldReceive('newQuery')->once()->andReturn($query); $query->shouldReceive('pluck')->once()->with('id')->andReturn(new BaseCollection([1, 2, 3])); // withoutGlobalScopes will get called exactly 3 times $relation->getRelated()->shouldReceive('withoutGlobalScopes')- >times(3)->andReturn($query); // Test deletions of items removed from relationship (1) $query->shouldReceive('whereIn')->once()->with('id', [1])- >andReturn($query); $query->shouldReceive('delete')->once()->andReturn($query); … // Check result $this->assertEquals(['created' => ['x'], 'deleted' => [1], 'updated' => [2,3]], $relation->sync($list)); }

Editor's Notes

  1. Some of these are not actually PHP. And some of these are not actually tools, in the conventional sense.
  2. The principal task of the software developer is to read (not write) code.
  3. Not going to cover everything, but particularly important are inline- and block code snippets
  4. How many of you have heard of the PHP Standards Recommendations? PHP Framework Interop Group – stress interop.
  5. PHP has a very flexible syntax - why should we make up arbitrary rules?
  6. PHP has a very flexible syntax - why should we make up arbitrary rules?
  7. PHP has a very flexible syntax - why should we make up arbitrary rules?
  8. Create your own internal documents!
  9. This was my "version control" - what are some of the problems here?
  10. Avoid "not invented here" syndrome
  11. Up until March of 2012, PHP didn't really have a good project-level package manager. There was PEAR, but it failed to keep up with the evolution of the PHP community. In March of 2012, on the heels of the PHP Standard Recommendations (PSR) project, Composer was released and a new era of PHP began. If you've been out of the PHP world for a while, you might have missed this critical shift. Over the past few years, Composer has risen to become the de facto package manager for PHP, with Packagist as its main public package repository. This means that the best way to incorporate third-party code (which you definitely should do) is by installing and using Composer - at the very least, in your development environment.
  12. Composer also handles autoloading, which means that the days of needing long blocks of include or require statements in your code are over. It fully implements the PSR-4 standard for autoloading, which further helps the PHP community develop a consistent approach to releasing and consuming packages.