@param $count

@return array
@throws Exception

API documentation: https://whatcounts.zendesk.com/hc/en-us/articles/203969759
761106
public function showCampaigns($count)
		{
			$form_data = array(
				'count' => $count,
				'headers' => 1
			);
			$data = $this->call('show_campaigns', $form_data, 'csv');
			$csv = new \parseCSV($data);

			$campaigns = array();

			foreach ($csv->data as $campaign_item) {
				$campaign = new Report();
				$campaign
					->setCampaignId((int)$campaign_item['Campaign ID'])
					->setListName((string)$campaign_item['List Name'])
					->setSubject((string)$campaign_item['Subject'])
					->setDate(\DateTime::createFromFormat('m/d/y h:i A', $campaign_item['Date']))
					->setRecipients((int)$campaign_item['Recipients']);

				$campaigns[] = $campaign;
			}
			return $campaigns;
		}
337492
protected function getRandomString($count)
    {
        // This string MUST stay FS safe, avoid special chars
        $base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
        $ret = '';
        $strlen = strlen($base);
        for ($i = 0; $i < $count; ++$i) {
            $ret .= $base[random_int(0, $strlen - 1)];
        }

        return $ret;
    }
304436
public function search($query, $count = null)
    {
        $params = ['query' => [
            'q'     => $query,
            'count' => $count,
        ]];

        return $this->client->request(
            'GET',
            'users/search',
            $params
        );
    }
1204884
protected function getListImageStyle($count = false)
    {
        $list = $this->image_style->getList();
        $allowed = $this->getAllowedFiltersImageStyle();

        $this->filterList($list, $allowed, $this->query_filter);
        $this->sortList($list, $allowed, $this->query_filter, array('name' => 'desc'));

        if ($count) {
            return count($list);
        }

        $this->limitList($list, $this->data_limit);
        $this->prepareListImageStyle($list);

        return $list;
    }
276808
public function list(int $lastId, int $count)
    {
        $params = [
            'type' => 2,
            'last_seen' => $lastId,
            'count' => $count,
        ];

        return $this->search($params);
    }
165905
public function readFloats($count)
    {
        $floats = array();

        for ($i = 0; $i < $count; $i++) {
            $float = $this->readFloat();

            if (! is_nan($float)) {
                $floats[] = $float;
            }
        }

        return $floats;
    }
1024364
protected function get_sql_and_params($count = false) {
        $fields = 'c.id, c.name, c.idnumber';

        if ($count) {
            $select = "COUNT(1)";
        } else {
            $select = "$fields";
        }

        $sql = "SELECT $select
                  FROM {" . \core_competency\template_cohort::TABLE . "} tc
                  JOIN {cohort} c ON c.id = tc.cohortid
                 WHERE tc.templateid = :templateid";
        $params = array('templateid' => $this->template->get('id'));

        // Add order by if needed.
        if (!$count && $sqlsort = $this->get_sql_sort()) {
            $sql .= " ORDER BY " . $sqlsort;
        }

        return array($sql, $params);
    }
577792
public function getConstrainedKeysByCount($count, $operator = '>=')
	{
		$associativeTable = $this->associativeTable;
		$associativeLocal = $this->associativeLocal;
		$shifter          = $this->shifter;
		$model            = $this->model;

		return $this->getConstrainedKeys(function($related) use ($count, $associativeTable, $associativeLocal, $shifter, $model, $operator)
		{
			$related->whereEquals($associativeTable . '.' . $shifter, strtolower($model->getModelName()))
			        ->group($shifter)
			        ->group($associativeLocal)
			        ->having('COUNT(*)', $operator, $count);
		});
	}
819290
public function list(int $begin, int $count)
    {
        $params = [
            'begin' => $begin,
            'count' => $count,
        ];

        return $this->httpPostJson('shakearound/device/group/getlist', $params);
    }
790017
public function build($count = false)
    {
        $modelNameSpace = $this->model->getModelNameSpace();
        $mm = $this->getDI()->get('modelsManager');
        $query = $mm->createBuilder()->from($modelNameSpace);

        // $columns = $this->model->getAllowedColumns(true);
        $columns = array(
            "$modelNameSpace.*"
        );

        // process hasOne Joins
        $this->queryJoinHelper($query);
        $this->querySearchHelper($query);
        $this->querySortHelper($query);

        if ($count) {
            $query->columns('count(*) as count');
        } else {
            // preserve any columns added through joins
            $existingColumns = $query->getColumns();
            $allColumns = array_merge($columns, $existingColumns);
            $query->columns($allColumns);
        }
        // skip limit if returning a count
        if (!$count) {
            $this->queryLimitHelper($query);
        }

        // todo build fields feature into PHQL instead of doing in PHP
        return $query;
    }
1338872
public static function count($count, array $options = []) {

        // TODO: Refactor the options to a dedicated config file.
        $classes = Arr::get($options, 'classes', [
            'positive' => 'label label-info',
            'zero'     => 'label label-default',
            'negative' => 'label label-danger',
        ]);

        return static::generate($count, [
            'class' => $count > 0 ? $classes['positive'] : ($count < 0 ? $classes['negative'] : $classes['zero'])
        ]);
    }
549393
public function getNodes($key, $count = 5)
    {
        // Degenerate cases
        if ($this->_nodeCount < $count) {
            throw new Exception('Not enough nodes (have ' . $this->_nodeCount . ', ' . $count . ' requested)');
        }
        if ($this->_nodeCount == 0) {
            return array();
        }

        // Simple case
        if ($this->_nodeCount == 1) {
            return array($this->_nodes[0]['n']);
        }

        $hash = $this->hash(serialize($key));

        // Find the first point on the circle greater than $hash by binary search.
        $low = 0;
        $high = $this->_pointCount - 1;
        $index = null;
        while (true) {
            $mid = (int)(($low + $high) / 2);
            if ($mid == $this->_pointCount) {
                $index = 0;
                break;
            }

            $midval = $this->_pointMap[$mid];
            $midval1 = ($mid == 0) ? 0 : $this->_pointMap[$mid - 1];
            if ($midval1 < $hash && $hash <= $midval) {
                $index = $mid;
                break;
            }

            if ($midval > $hash) {
                $high = $mid - 1;
            } else {
                $low = $mid + 1;
            }

            if ($low > $high) {
                $index = 0;
                break;
            }
        }

        $nodes = array();
        while (count($nodes) < $count) {
            $nodeIndex = $this->_pointMap[$index++ % $this->_pointCount];
            $nodes[$nodeIndex] = $this->_nodes[$this->_circle[$nodeIndex]]['n'];
        }
        return array_values($nodes);
    }
717594
protected function getListReportShipping($count = false)
    {
        $list = $this->shipping->getList();
        $allowed = $this->getAllowedFiltersReportShipping();

        $this->filterList($list, $allowed, $this->query_filter);
        $this->sortList($list, $allowed, $this->query_filter, array('id' => 'asc'));

        if ($count) {
            return count($list);
        }

        $this->limitList($list, $this->data_limit);
        return $list;
    }
487572
protected function getSqlForSelect($count = false)
    {
        $parts = $this->sqlParts;

        if (!$parts['select']) {
            $parts['select'] = array('*');
        }

        $query = 'SELECT ' . implode(', ', $parts['select']) . ' FROM ' . $this->getFrom();

        // JOIN
        foreach ($parts['join'] as $join) {
            $query .= ' ' . strtoupper($join['type'])
                . ' JOIN ' . $join['table']
                . ' ON ' . $join['on'];
        }

        $query .= ($parts['where'] !== null ? ' WHERE ' . ((string)$parts['where']) : '')
            . ($parts['groupBy'] ? ' GROUP BY ' . implode(', ', $parts['groupBy']) : '')
            . ($parts['having'] !== null ? ' HAVING ' . ((string)$parts['having']) : '');

        if (false === $count) {
            $query .= ($parts['orderBy'] ? ' ORDER BY ' . implode(', ', $parts['orderBy']) : '')
                . ($parts['limit'] !== null ? ' LIMIT ' . $parts['limit'] : '')
                . ($parts['offset'] !== null ? ' OFFSET ' . $parts['offset'] : '');
        }

        $query .= $this->generateLockSql();

        return $query;
    }
109497
private function generateCustomers($count)
    {
        $customers = [];

        for ($i = 0; $i < $count; ++$i) {
            /** @var CustomerInterface $customer */
            $customer = $this->customerFactory->createNew();
            $customer->setEmail(sprintf('john%s@doe.com', uniqid()));
            $customer->setFirstname('John');
            $customer->setLastname('Doe' . $i);

            $customers[] = $customer;

            $this->customerRepository->add($customer);
        }

        return $customers;
    }
917411
public function stream_read($count)
    {
        $ret = substr($this->_data, $this->_pos, $count);
        $this->_pos += strlen($ret);
        return $ret;
    }
1140584
public function takeLast(int $count)
    {
        return $this->wrap(function (Iterator $data) use ($count) {
            // From the end of the collection
            $limit = max(0, $count);
            $chunk = [];

            foreach ($data as $key => $datum) {
                $chunk[] = [$key, $datum];
                if (count($chunk) > $limit) {
                    array_shift($chunk);
                }
            }

            foreach ($chunk as $item) {
                [$key, $datum] = $item;
                yield $key => $datum;
            }
        });
    }