Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProtCommand
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 run
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2namespace Apie\FtpServer\Commands;
3
4use Apie\Core\Context\ApieContext;
5use Apie\FtpServer\Factories\ImplicitSslFtpServerFactory;
6use Apie\FtpServer\Factories\ServerFactoryInterface;
7use React\Socket\ConnectionInterface;
8
9class ProtCommand implements CommandInterface
10{
11    public function run(ApieContext $apieContext, string $arg = ''): ApieContext
12    {
13        $conn = $apieContext->getContext(ConnectionInterface::class);
14        $arg = strtoupper(trim($arg));
15        $serverFactory = $apieContext->getContext(ServerFactoryInterface::class, false);
16        if ($serverFactory instanceof ImplicitSslFtpServerFactory) {
17            $conn->write(
18                $arg === 'P'
19                ? "200 Protection level set to Private (TLS/SSL)\r\n"
20                : "534 Only 'Private' protection level is supported.\r\n"
21            );
22        } else {
23            $conn->write(
24                $arg === 'C'
25                ? "200 Protection level set to Clear\r\n"
26                : "534 Only 'Clear' protection level is supported.\r\n"
27            );
28        }
29        return $apieContext;
30    }
31}