Permalink
Browse files

Apply php-cs-fixer

* Apply php-cs-fixer
* Use short array syntax
  • Loading branch information...
1 parent 7796cf7 commit 8595d2342bf624053c490b52514dc17493d5425b @shinework shinework committed Apr 6, 2016
View
@@ -1,37 +1,38 @@
<?php
-$loader = require_once __DIR__ . '/../vendor/autoload.php';
-$loader->add('Joli\ArDrone', __DIR__ . '/../src/');
+
+$loader = require_once __DIR__.'/../vendor/autoload.php';
+$loader->add('Joli\ArDrone', __DIR__.'/../src/');
$client = new \Joli\ArDrone\Client();
$client->takeoff();
$client
- ->after(3, function() use ($client) {
+ ->after(3, function () use ($client) {
$client->up(0.6);
})
- ->after(4, function() use ($client) {
+ ->after(4, function () use ($client) {
$client->stop();
})
- ->after(1, function() use ($client) {
+ ->after(1, function () use ($client) {
$client->left(0.3);
})
- ->after(1, function() use ($client) {
+ ->after(1, function () use ($client) {
$client->stop();
})
- ->after(1, function() use ($client) {
+ ->after(1, function () use ($client) {
$client->down(0.5);
})
- ->after(2, function() use ($client) {
+ ->after(2, function () use ($client) {
$client->stop();
})
- ->after(1, function() use ($client) {
+ ->after(1, function () use ($client) {
$client->right(0.3);
})
- ->after(1, function() use ($client) {
+ ->after(1, function () use ($client) {
$client->stop();
})
- ->after(3, function() use ($client) {
+ ->after(3, function () use ($client) {
$client->land();
});
View
@@ -1,6 +1,7 @@
<?php
-$loader = require_once __DIR__ . '/../vendor/autoload.php';
-$loader->add('Joli\ArDrone', __DIR__ . '/../src/');
+
+$loader = require_once __DIR__.'/../vendor/autoload.php';
+$loader->add('Joli\ArDrone', __DIR__.'/../src/');
$client = new \Joli\ArDrone\Client();
@@ -1,7 +1,9 @@
<?php
+
namespace Joli\ArDrone\Buffer;
-class Buffer {
+class Buffer
+{
/**
* @var string
*/
@@ -20,38 +22,39 @@ public function __construct($binary)
public function getUint32LE()
{
- $value = unpack('V/', substr($this->data, $this->offset, ($this->offset + 4)));
+ $value = unpack('V/', substr($this->data, $this->offset, ($this->offset + 4)));
$this->moveOffset(4);
+
return dechex($value[1]);
}
public function getUint16LE()
{
- $value = unpack('v/', substr($this->data, $this->offset, ($this->offset + 2)));
+ $value = unpack('v/', substr($this->data, $this->offset, ($this->offset + 2)));
$this->moveOffset(2);
return dechex($value[1]);
}
public function getFloat32()
{
- $value = unpack('f/', substr($this->data, $this->offset, ($this->offset + 4)));
+ $value = unpack('f/', substr($this->data, $this->offset, ($this->offset + 4)));
$this->moveOffset(4);
return dechex($value[1]);
}
public function getUint8()
{
- $value = unpack('C/', substr($this->data, $this->offset, ($this->offset + 1)));
+ $value = unpack('C/', substr($this->data, $this->offset, ($this->offset + 1)));
$this->moveOffset(1);
return dechex($value[1]);
}
public function getInt32()
{
- $value = unpack('I/', substr($this->data, $this->offset, ($this->offset + 4)));
+ $value = unpack('I/', substr($this->data, $this->offset, ($this->offset + 4)));
$this->moveOffset(4);
return dechex($value[1]);
@@ -62,16 +65,18 @@ public function getMask32($masks)
return $this->mask($masks, $this->getUint32LE());
}
- public function getVector31() {
- return array(
+ public function getVector31()
+ {
+ return [
'x' => $this->getFloat32(),
'y' => $this->getFloat32(),
'z' => $this->getFloat32(),
- );
+ ];
}
- public function getMatrix33() {
- return array(
+ public function getMatrix33()
+ {
+ return [
'm11' => $this->getFloat32(),
'm12' => $this->getFloat32(),
'm13' => $this->getFloat32(),
@@ -81,7 +86,7 @@ public function getMatrix33() {
'm31' => $this->getFloat32(),
'm32' => $this->getFloat32(),
'm33' => $this->getFloat32(),
- );
+ ];
}
public function getBytes($nbBytes)
@@ -100,13 +105,13 @@ private function moveOffset($step)
//todo: move this function ?
private function mask($masks, $value)
{
- $flags = array();
+ $flags = [];
- foreach($masks as $name => $mask) {
+ foreach ($masks as $name => $mask) {
$flags[$name] = (hexdec($value) & ($mask)) ? 1 : 0;
}
- return $flags;
+ return $flags;
}
/**
@@ -117,7 +122,8 @@ public function getData()
return $this->data;
}
- public function getLength() {
+ public function getLength()
+ {
return strlen($this->data);
}
}
@@ -1,15 +1,17 @@
<?php
+
namespace Joli\ArDrone;
use Evenement\EventEmitter;
use Joli\ArDrone\Control\UdpControl;
use Joli\ArDrone\Navdata\Frame;
use Joli\ArDrone\Navdata\UdpNavdata;
-use React\EventLoop\Factory AS LoopFactory;
-use React\Datagram\Factory AS UdpFactory;
+use React\EventLoop\Factory as LoopFactory;
+use React\Datagram\Factory as UdpFactory;
use Joli\ArDrone\Config\Config;
-class Client extends EventEmitter {
+class Client extends EventEmitter
+{
/**
* @var \Joli\ArDrone\Control\UdpControl
*/
@@ -26,7 +28,7 @@ class Client extends EventEmitter {
private $timerOffset;
/**
- * @var boolean
+ * @var bool
*/
public $disableEmergency;
@@ -52,12 +54,12 @@ class Client extends EventEmitter {
public function __construct()
{
- $this->loop = LoopFactory::create();
+ $this->loop = LoopFactory::create();
- $this->udpFactory = new UdpFactory($this->loop);
- $this->timerOffset = 0;
- $this->lastState = 'CTRL_LANDED';
- $this->lastBattery = 100;
+ $this->udpFactory = new UdpFactory($this->loop);
+ $this->timerOffset = 0;
+ $this->lastState = 'CTRL_LANDED';
+ $this->lastBattery = 100;
$this->lastAltitude = 0;
$this->disableEmergency = false;
@@ -70,7 +72,7 @@ public function startUdpNavdata()
$this->udpNavdata = new UdpNavdata($this->loop);
$self = $this;
- $this->udpNavdata->on('navdata', function(Frame $navdata) use (&$self) {
+ $this->udpNavdata->on('navdata', function (Frame $navdata) use (&$self) {
if (count($navdata->getDroneState()) > 0) {
$stateData = $navdata->getDroneState();
if ($stateData['emergencyLanding'] && $self->disableEmergency) {
@@ -102,31 +104,31 @@ public function startUdpNavdata()
$stateData = $navdata->getDroneState();
if ($stateData['lowBattery'] === 1) {
- $self->emit('lowBattery', array($battery));
+ $self->emit('lowBattery', [$battery]);
}
if ($battery !== $self->lastBattery) {
- $self->emit('batteryChange', array($battery));
+ $self->emit('batteryChange', [$battery]);
$self->lastBattery = $battery;
}
// altitude events
$altitude = $demoData['altitudeMeters'];
if ($altitude !== $self->lastAltitude) {
- $self->emit('altitudeChange', array($altitude));
+ $self->emit('altitudeChange', [$altitude]);
$self->lastAltitude = $altitude;
}
}
- $self->emit('navdata', array($navdata));
+ $self->emit('navdata', [$navdata]);
});
}
public function emitState($e, $state, $currentState)
{
if ($currentState === $state && $this->lastState !== $state) {
- $this->emit($e, array());
+ $this->emit($e, []);
}
}
@@ -142,7 +144,7 @@ public function createRepl()
$udpControl = $this->udpControl;
- $repl->on('action', function($action) use (&$udpControl) {
+ $repl->on('action', function ($action) use (&$udpControl) {
$udpControl->emit($action);
});
}
@@ -178,23 +180,23 @@ public function start()
public function __call($name, $arguments)
{
- if(in_array($name, Config::$commands)) {
+ if (in_array($name, Config::$commands)) {
if ($name === 'takeoff' || $name === 'land') {
// process callback function
- $callback = (count($arguments) === 1) ? $arguments[0] : function() {};
+ $callback = (count($arguments) === 1) ? $arguments[0] : function () {};
$eventName = ($name === 'takeoff') ? 'hovering' : 'landed';
$this->once($eventName, $callback);
$this->udpControl->emit($name);
- } else if ($name === 'stop' || $name === 'ftrim' || $name === 'flip') {
+ } elseif ($name === 'stop' || $name === 'ftrim' || $name === 'flip') {
$this->udpControl->emit($name);
// Control commands
} else {
if (count($arguments) > 1) {
new \Exception('There are too many arguments');
}
- $this->udpControl->emit($name, array($arguments[0]));
+ $this->udpControl->emit($name, [$arguments[0]]);
}
} else {
new \Exception('Invalid function');
@@ -1,13 +1,14 @@
<?php
-namespace Joli\ArDrone\Config;
-class Config {
+namespace Joli\ArDrone\Config;
+class Config
+{
const DRONE_IP = '192.168.1.1';
const NAVDATA_PORT = 5554;
const CONTROL_PORT = 5556;
- static $commands = array(
+ public static $commands = [
'takeoff',
'land',
'clockwise',
@@ -21,6 +22,6 @@ class Config {
'stop',
'exit',
'ftrim',
- 'flip'
- );
+ 'flip',
+ ];
}
@@ -1,8 +1,9 @@
<?php
-namespace Joli\ArDrone\Control;
-class AtCommand {
+namespace Joli\ArDrone\Control;
+class AtCommand
+{
/**
* @var string
*/
@@ -18,31 +19,30 @@ class AtCommand {
*/
private $sequence;
- const TYPE_REF = 'REF';
- const TYPE_PCMD = 'PCMD';
- const TYPE_CALIB = 'CALIB';
+ const TYPE_REF = 'REF';
+ const TYPE_PCMD = 'PCMD';
+ const TYPE_CALIB = 'CALIB';
const TYPE_CONFIG = 'CONFIG';
- const TYPE_FTRIM = 'FTRIM';
- const TYPE_ANIM = 'ANIM';
+ const TYPE_FTRIM = 'FTRIM';
+ const TYPE_ANIM = 'ANIM';
public function __construct($sequence, $type, $args)
{
- $this->args = $args;
- $this->type = $type;
+ $this->args = $args;
+ $this->type = $type;
$this->sequence = $sequence;
}
- function __toString()
+ public function __toString()
{
- $command = 'AT*' . $this->type . '=' . $this->sequence;
+ $command = 'AT*'.$this->type.'='.$this->sequence;
if (count($this->args) > 0) {
- $command .= ','. implode(',', $this->args);
+ $command .= ','.implode(',', $this->args);
}
$command .= "\r";
return $command;
}
-
}
Oops, something went wrong.

0 comments on commit 8595d23

Please sign in to comment.