Skip to content

Instantly share code, notes, and snippets.

@adelatorrefoss
Created May 17, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adelatorrefoss/104955bb0d01037fe2293dd73f782583 to your computer and use it in GitHub Desktop.
Save adelatorrefoss/104955bb0d01037fe2293dd73f782583 to your computer and use it in GitHub Desktop.
POST REFACTOR
<?php
namespace Trovit\B2B\Redirect\Tests\integration\Controller;
class QueryStringBuilder
{
const CONNECTOR = '&';
const START = '/?';
private $brand;
private $vertical;
private $country;
private $sourceId;
private $page;
private $pageViewId;
private $what;
private $userIp;
private $userAgent;
private $isHuman;
private $isDirified;
private $origin;
private $browser;
private $section;
public static function requestParameters()
{
$builder = new QueryStringBuilder();
$builder->brand = "1";
$builder->vertical = "2";
$builder->country = "es";
$builder->sourceId = "1";
$builder->page = "3";
$builder->pageViewId = "0";
$builder->what = "lalala";
$builder->userIp = "192.0.0.1";
$builder->userAgent = "Netscape 9.0";
$builder->isHuman = "false";
$builder->isDirified = "false";
$builder->origin = "0";
$builder->browser = "1";
$builder->section = "26";
return $builder;
}
public function build()
{
return self::START .
$this->addParameter("pageViewId", $this->pageViewId) .
$this->addParameter("brand", $this->brand) .
$this->addParameter("userIp", $this->userIp) .
$this->addParameter("userAgent", $this->userAgent) .
$this->addParameter("vertical", $this->vertical) .
$this->addParameter("page", $this->page) .
$this->addParameter("sourceId", $this->sourceId) .
$this->addParameter("country", $this->country) .
$this->addParameter("section", $this->section) .
$this->addParameter("what", $this->what).
$this->addParameter("origin", $this->origin).
$this->addParameter("browser", $this->browser).
$this->addParameter("isDirified", $this->isDirified).
$this->addParameter("isHuman", $this->isHuman);
}
public function withoutBrand()
{
$this->brand = null;
return $this;
}
public function withoutCountry()
{
$this->country = null;
return $this;
}
public function withoutVertical()
{
$this->vertical = null;
return $this;
}
public function withoutPage()
{
$this->page = null;
return $this;
}
public function withoutSourceId()
{
$this->sourceId = null;
return $this;
}
private function addParameter($name, $value): string
{
if (is_null($value)) {
return "";
}
return "{$name}={$value}" . self::CONNECTOR;
}
public function withoutPageViewId()
{
$this->pageViewId = null;
return $this;
}
public function withoutWhat()
{
$this->what = null;
return $this;
}
public function withoutUserIp()
{
$this->userIp = null;
return $this;
}
public function withoutUserAgent()
{
$this->userAgent = null;
return $this;
}
public function withoutIsHuman()
{
$this->isHuman = null;
return $this;
}
public function withoutIsDirified()
{
$this->isDirified = null;
return $this;
}
public function withoutOrigin()
{
$this->origin = null;
return $this;
}
public function withoutBrowser()
{
$this->browser = null;
return $this;
}
public function withoutSection()
{
$this->section = null;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment