Skip to content

Commit

Permalink
Merge pull request bschmitt#30 from blanxii/refactor-to-follow-psr2
Browse files Browse the repository at this point in the history
Add standard for PSR2 support
  • Loading branch information
bschmitt authored Oct 29, 2017
2 parents 66197d3 + a7c24f4 commit 16b4ff9
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 41 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9"
"mockery/mockery": "~0.9",
"squizlabs/php_codesniffer": "^3.0@dev"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 3 additions & 2 deletions src/Amqp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp;
<?php

namespace Bschmitt\Amqp;

use Closure;
use Bschmitt\Amqp\Request;
Expand Down Expand Up @@ -62,5 +64,4 @@ public function message($body, $properties = [])
{
return new Message($body, $properties);
}

}
6 changes: 3 additions & 3 deletions src/AmqpServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp;
<?php

namespace Bschmitt\Amqp;

use Bschmitt\Amqp\Consumer;
use Bschmitt\Amqp\Publisher;
Expand Down Expand Up @@ -40,7 +42,6 @@ public function register()
$this->app->singleton('Bschmitt\Amqp\Consumer', function ($app) {
return new Consumer(config());
});

}

/**
Expand All @@ -52,5 +53,4 @@ public function provides()
{
return ['Amqp', 'Bschmitt\Amqp\Publisher', 'Bschmitt\Amqp\Consumer'];
}

}
14 changes: 8 additions & 6 deletions src/Consumer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp;
<?php

namespace Bschmitt\Amqp;

use Illuminate\Config\Repository;
use Closure;
Expand All @@ -24,7 +26,6 @@ class Consumer extends Request
public function consume($queue, Closure $closure)
{
try {

$this->messageCount = $this->getQueueMessageCount();

if (!$this->getProperty('persistent') && $this->messageCount == 0) {
Expand Down Expand Up @@ -57,11 +58,13 @@ function ($message) use ($closure, $object) {

// consume
while (count($this->getChannel()->callbacks)) {
$this->getChannel()->wait(NULL, !$this->getProperty('blocking'), $this->getProperty('timeout') ? $this->getProperty('timeout') : 0);
$this->getChannel()->wait(
null,
!$this->getProperty('blocking'),
$this->getProperty('timeout') ? $this->getProperty('timeout') : 0
);
}

} catch (\Exception $e) {

if ($e instanceof Exception\Stop) {
return true;
}
Expand Down Expand Up @@ -112,5 +115,4 @@ public function stopWhenProcessed()
throw new Exception\Stop();
}
}

}
10 changes: 5 additions & 5 deletions src/Context.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php namespace Bschmitt\Amqp;
<?php

namespace Bschmitt\Amqp;

use Illuminate\Config\Repository;
use PhpAmqpLib\Connection\AMQPStreamConnection;

/**
* @author Björn Schmitt <[email protected]>
Expand Down Expand Up @@ -61,12 +62,11 @@ public function getProperties()
*/
public function getProperty($key)
{
return array_key_exists($key, $this->properties) ? $this->properties[$key] : NULL;
return array_key_exists($key, $this->properties) ? $this->properties[$key] : null;
}

/**
* @return mixed
*/
abstract function setup();

abstract public function setup();
}
4 changes: 3 additions & 1 deletion src/Exception/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp\Exception;
<?php

namespace Bschmitt\Amqp\Exception;

/**
* @author Björn Schmitt <[email protected]>
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/Stop.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php namespace Bschmitt\Amqp\Exception;
<?php

namespace Bschmitt\Amqp\Exception;

/**
* @author Björn Schmitt <[email protected]>
*/
class Stop extends \Exception
{

}
}
7 changes: 4 additions & 3 deletions src/Facades/Amqp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp\Facades;
<?php

namespace Bschmitt\Amqp\Facades;

use Illuminate\Support\Facades\Facade;

Expand All @@ -16,5 +18,4 @@ protected static function getFacadeAccessor()
{
return 'Amqp';
}

}
}
8 changes: 4 additions & 4 deletions src/LumenServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp;
<?php

namespace Bschmitt\Amqp;

use Illuminate\Support\ServiceProvider;

Expand All @@ -17,7 +19,6 @@ class LumenServiceProvider extends ServiceProvider
*/
public function boot()
{

}

/**
Expand All @@ -41,5 +42,4 @@ public function register()
class_alias('Bschmitt\Amqp\Facades\Amqp', 'Amqp');
}
}

}
}
6 changes: 4 additions & 2 deletions src/Message.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace Bschmitt\Amqp;
<?php

use \PhpAmqpLib\Message\AMQPMessage;
namespace Bschmitt\Amqp;

use PhpAmqpLib\Message\AMQPMessage;

/**
* @author Björn Schmitt <[email protected]>
Expand Down
5 changes: 2 additions & 3 deletions src/Publisher.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace Bschmitt\Amqp;
<?php

use Illuminate\Config\Repository;
namespace Bschmitt\Amqp;

/**
* @author Björn Schmitt <[email protected]>
Expand All @@ -17,5 +17,4 @@ public function publish($routing, $message)
{
$this->getChannel()->basic_publish($message, $this->getProperty('exchange'), $routing);
}

}
16 changes: 8 additions & 8 deletions src/Request.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Bschmitt\Amqp;
<?php

namespace Bschmitt\Amqp;

use Illuminate\Config\Repository;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Connection\AMQPSSLConnection;
use PhpAmqpLib\Channel\AMQPChannel;
Expand Down Expand Up @@ -64,7 +65,6 @@ public function setup()
durable: true // the exchange will survive server restarts
auto_delete: false //the exchange won't be deleted once the channel is closed.
*/

$this->channel->exchange_declare(
$exchange,
$this->getProperty('exchange_type'),
Expand All @@ -79,7 +79,6 @@ public function setup()
$queue = $this->getProperty('queue');

if (!empty($queue) || $this->getProperty('queue_force_declare')) {

/*
name: $queue
passive: false
Expand All @@ -101,10 +100,12 @@ public function setup()
$this->getProperty('queue_properties')
);

$this->channel->queue_bind($queue ?: $this->queueInfo[0], $exchange, $this->getProperty('routing'));

$this->channel->queue_bind(
$queue ?: $this->queueInfo[0],
$exchange,
$this->getProperty('routing')
);
}

// clear at shutdown
register_shutdown_function([get_class(), 'shutdown'], $this->channel, $this->connection);
}
Expand Down Expand Up @@ -145,5 +146,4 @@ public static function shutdown(AMQPChannel $channel, AMQPStreamConnection $conn
$channel->close();
$connection->close();
}

}
4 changes: 3 additions & 1 deletion test/SimpleTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Bschmitt\Amqp\Test;
<?php

namespace Bschmitt\Amqp\Test;

/**
* @author Björn Schmitt <[email protected]>
Expand Down

0 comments on commit 16b4ff9

Please sign in to comment.