Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TypeCommand
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 run
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\FtpServer\Commands;
3
4use Apie\Core\Context\ApieContext;
5use Apie\FtpServer\FtpConstants;
6use React\Socket\ConnectionInterface;
7
8class TypeCommand implements CommandInterface
9{
10    public function run(ApieContext $apieContext, string $arg = ''): ApieContext
11    {
12        $conn = $apieContext->getContext(ConnectionInterface::class);
13        $type = strtoupper(trim($arg));
14        if ($type === 'A') {
15            $conn->write("200 Type set to A (ASCII)\r\n");
16            return $apieContext->withContext(FtpConstants::FTP_TYPE, 'A');
17        } elseif ($type === 'I') {
18            $conn->write("200 Type set to I (Binary)\r\n");
19            return $apieContext->withContext(FtpConstants::FTP_TYPE, 'I');
20        }
21        $conn->write("504 Command not implemented for that parameter\r\n");
22        return $apieContext;
23    }
24}