Skip to content

Commit 56e41ae

Browse files
committed
Fixed REST server boot router
1 parent b94721b commit 56e41ae

File tree

6 files changed

+42
-45
lines changed

6 files changed

+42
-45
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,11 @@ public probabilities() : array
559559
**Example:**
560560

561561
```php
562-
use Rubix\Server\Responses\ProbasSampleResponse;
562+
use Rubix\Server\Responses\ProbaSampleResponse;
563563

564564
// Obtain probabilities from model
565565

566-
$response = new ProbaampleResponse($probabilities);
566+
$response = new ProbaSampleResponse($probabilities);
567567
```
568568

569569
### Query Model Response

src/CommandBus.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ public function __construct(array $mapping)
3737
{
3838
foreach ($mapping as $command => $handler) {
3939
if (!class_exists($command)) {
40-
throw new InvalidArgumentException("$command does"
41-
. ' not exist.');
40+
throw new InvalidArgumentException("$command does not exist.");
4241
}
4342

4443
if (!$handler instanceof Handler) {
4544
throw new InvalidArgumentException('Command must map'
46-
. ' to a handler, ' . get_class($handler)
47-
. ' given.');
45+
. ' to a handler, ' . get_class($handler) . ' given.');
4846
}
4947
}
5048

src/RESTServer.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -290,36 +290,35 @@ function ($group) use ($estimator, $bus) {
290290
new PredictionsController($bus)
291291
);
292292

293-
switch (true) {
294-
case $estimator instanceof Learner:
295-
$group->post(
296-
self::PREDICT_SAMPLE_ENDPOINT,
297-
new SamplePredictionController($bus)
298-
);
293+
if ($estimator instanceof Learner) {
294+
$group->post(
295+
self::PREDICT_SAMPLE_ENDPOINT,
296+
new SamplePredictionController($bus)
297+
);
298+
}
299299

300-
// no break
301-
case $estimator instanceof Probabilistic:
302-
$group->post(
303-
self::PROBA_ENDPOINT,
304-
new ProbabilitiesController($bus)
305-
);
306-
307-
$group->post(
308-
self::PROBA_SAMPLE_ENDPOINT,
309-
new SampleProbabilitiesController($bus)
310-
);
311-
312-
// no break
313-
case $estimator instanceof Ranking:
314-
$group->post(
315-
self::RANK_ENDPOINT,
316-
new ScoresController($bus)
317-
);
318-
319-
$group->post(
320-
self::RANK_SAMPLE_ENDPOINT,
321-
new SampleScoreController($bus)
322-
);
300+
if ($estimator instanceof Probabilistic) {
301+
$group->post(
302+
self::PROBA_ENDPOINT,
303+
new ProbabilitiesController($bus)
304+
);
305+
306+
$group->post(
307+
self::PROBA_SAMPLE_ENDPOINT,
308+
new SampleProbabilitiesController($bus)
309+
);
310+
}
311+
312+
if ($estimator instanceof Ranking) {
313+
$group->post(
314+
self::RANK_ENDPOINT,
315+
new ScoresController($bus)
316+
);
317+
318+
$group->post(
319+
self::RANK_SAMPLE_ENDPOINT,
320+
new SampleScoreController($bus)
321+
);
323322
}
324323
}
325324
);

src/RPCClient.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ public function send(Command $command) : Response
176176
$response = $this->serializer->unserialize($payload);
177177

178178
if (!$response instanceof Response) {
179-
throw new RuntimeException('Response could not'
180-
. ' be reconstituted.');
179+
throw new RuntimeException('Message is not a valid response.');
181180
}
182181

183182
return $response;

src/Responses/ProbaSampleResponse.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public static function fromArray(array $data) : self
3333
}
3434

3535
/**
36-
* @param mixed $probabilities
36+
* @param array $probabilities
3737
*/
38-
public function __construct($probabilities)
38+
public function __construct(array $probabilities)
3939
{
4040
$this->probabilities = $probabilities;
4141
}
4242

4343
/**
4444
* Return the probabilities.
4545
*
46-
* @return mixed
46+
* @return array
4747
*/
48-
public function probabilities()
48+
public function probabilities() : array
4949
{
5050
return $this->probabilities;
5151
}

src/Serializers/Json.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public function unserialize(string $data) : Message
2929
{
3030
$json = json_decode($data, true);
3131

32-
if (isset($json['name']) and class_exists($json['name'])) {
33-
return $json['name']::fromArray($json['data'] ?? []);
32+
$class = $json['name'] ?? null;
33+
34+
if ($class and class_exists($class)) {
35+
return $class::fromArray($json['data'] ?? []);
3436
}
3537

36-
throw new RuntimeException('Message could not be'
37-
. ' reconstituted.');
38+
throw new RuntimeException('Message could not be reconstituted.');
3839
}
3940
}

0 commit comments

Comments
 (0)