<?php

namespace Qafoo\Analyzer\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Serve extends Command
{
    protected function configure()
    {
        $this
            ->setName('serve')
            ->setDescription('Serve application')
            ->addOption(
                'port',
                'p',
                InputOption::VALUE_REQUIRED,
                'Port to start webserver on',
                8080
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $port = (int) $input->getOption('port');
        $baseDir = realpath(__DIR__ . '/../../../../../');
        $output->writeln("Starting webserver on http://localhost:$port/");
        passthru("/usr/bin/env php -S localhost:$port -t $baseDir $baseDir/bin/serve.php");
    }
}

<?php

namespace Qafoo\Analyzer\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Serve extends Command
{
    protected function configure()
    {
        $this
            ->setName('serve')
            ->setDescription('Serve application')
            ->addOption(
                'port',
                'p',
                InputOption::VALUE_REQUIRED,
                'Port to start webserver on',
                8080
            )
            ->addOption(
                'hostname',
                null, // -h is already used for help
                InputOption::VALUE_REQUIRED,
                'Hostname used to listen to',
                'localhost'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $port = (int) $input->getOption('port');
        $hostname = $input->getOption('hostname');
        $baseDir = realpath(__DIR__ . '/../../../../../');
        $output->writeln("Starting webserver on http://$hostname:$port/");
        passthru("/usr/bin/env php -S $hostname:$port -t $baseDir $baseDir/bin/serve.php");
    }
}

Allow setting the hostname via a -h flag
Allow setting the hostname via a -h flag

This should make it possible to use the app from i.e. inside a (docker) container for easy running...
``` docker run -it --rm -v $(pwd):/app -w /app -p 80:8080 php:7-cli bin/analyze serve --hostname 0.0.0.0 ```