<commit_before><?php
namespace App\Shell;

use App\View\PdfView;
use Cake\Console\ConsoleIo;
use Cake\Console\Shell;
use Cake\Filesystem\File;

/**
 * Simple console wrapper around Psy\Shell.
 */
class QueueShell extends Shell
{

	public function initialize()
	{
		parent::initialize();
		$this->_io->level(ConsoleIo::QUIET);
		$this->loadModel('Lammies');
	}

	public function main()
	{
		$result = $this->Lammies->find('lastInQueue')->all();
		if($result->count() == 0)
			$this->quiet(0);
		else
			$this->quiet($result->first()->id);
	}

    public function single($id = 0, $filename = NULL)
    {
		$this->createPdf($id, $filename);
    }

    public function double($id = 0, $filename = NULL)
    {
		$this->createPdf($id, $filename, true);
    }

	private function createPdf($id, $filename, $double = false)
	{
		$query = $this->Lammies->find('queued');
		$query->where(["Lammies.id <=" => $id]);
		$lammies = $query->all();
		if($lammies->count() == 0)
			return;

		$this->Lammies->setStatuses($lammies, 'Printing');

		$lammies = $lammies->map(function($value, $key) {
				return $value->lammy;
			})->toArray();

		if(empty($filename)) {
			$this->quiet((new PdfView())->createPdf($lammies, $double));
			return;
		}

		$file = new File($filename, true);
		$file->write((new PdfView())->createPdf($lammies, $double));
		$file->close();
	}

	public function printed($id)
	{
		$lammies = $this->Lammies->find('printing')->all();
		$this->Lammies->setStatuses($lammies, 'Printed');
		$this->quiet($lammies->count());
	}

}<commit_msg>style cleanup<commit_after><?php
namespace App\Shell;

use App\View\PdfView;
use Cake\Console\ConsoleIo;
use Cake\Console\Shell;
use Cake\Filesystem\File;

class QueueShell extends Shell
{
	public function initialize()
	{
		parent::initialize();
		$this->_io->level(ConsoleIo::QUIET);
		$this->loadModel('Lammies');
	}

	public function main()
	{
		$result = $this->Lammies->find('lastInQueue')->all();
		if($result->count() == 0)
			$this->quiet(0);
		else
			$this->quiet($result->first()->id);
	}

	public function single($id = 0, $filename = NULL)
	{
		$this->createPdf($id, $filename);
	}

	public function double($id = 0, $filename = NULL)
	{
		$this->createPdf($id, $filename, true);
	}

	private function createPdf($id, $filename, $double = false)
	{
		$query = $this->Lammies->find('queued');
		$query->where(["Lammies.id <=" => $id]);
		$lammies = $query->all();
		if($lammies->count() == 0)
			return;

		$this->Lammies->setStatuses($lammies, 'Printing');

		$lammies = $lammies->map(function($value, $key) {
				return $value->lammy;
			})->toArray();

		if(empty($filename)) {
			$this->quiet((new PdfView())->createPdf($lammies, $double));
			return;
		}

		$file = new File($filename, true);
		$file->write((new PdfView())->createPdf($lammies, $double));
		$file->close();
	}

	public function printed($id)
	{
		$lammies = $this->Lammies->find('printing')->all();
		$this->Lammies->setStatuses($lammies, 'Printed');
		$this->quiet($lammies->count());
	}
}
{'fraction_non_alphanumeric': 0.21713147410358566, 'fraction_numerical': 0.0033200531208499337, 'mean_word_length': 4.3612099644128115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5076341', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1118, 'n_words': 190}