mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-07 22:46:39 +02:00
Tweak example code for PSR-1/PSR-2 coding standard
This commit is contained in:
@@ -21,18 +21,18 @@ the object you want to use. Consider the following example of the factory patter
|
|||||||
<?php
|
<?php
|
||||||
class Automobile
|
class Automobile
|
||||||
{
|
{
|
||||||
private $vehicle_make;
|
private $vehicleMake;
|
||||||
private $vehicle_model;
|
private $vehicleModel;
|
||||||
|
|
||||||
public function __construct($make, $model)
|
public function __construct($make, $model)
|
||||||
{
|
{
|
||||||
$this->vehicle_make = $make;
|
$this->vehicleMake = $make;
|
||||||
$this->vehicle_model = $model;
|
$this->vehicleModel = $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_make_and_model()
|
public function getMakeAndModel()
|
||||||
{
|
{
|
||||||
return $this->vehicle_make . ' ' . $this->vehicle_model;
|
return $this->vehicleMake . ' ' . $this->vehicleModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ class AutomobileFactory
|
|||||||
// have the factory create the Automobile object
|
// have the factory create the Automobile object
|
||||||
$veyron = AutomobileFactory::create('Bugatti', 'Veyron');
|
$veyron = AutomobileFactory::create('Bugatti', 'Veyron');
|
||||||
|
|
||||||
print_r($veyron->get_make_and_model()); // outputs "Bugatti Veyron"
|
print_r($veyron->getMakeAndModel()); // outputs "Bugatti Veyron"
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
This code uses a factory to create the Automobile object. There are two possible benefits to building your code this
|
This code uses a factory to create the Automobile object. There are two possible benefits to building your code this
|
||||||
|
Reference in New Issue
Block a user