Resolves post_category arg into an array of category ids.

@param string $arg Supplied argument.
@return array
4552
private function get_category_ids( $arg ) {

		$categories   = explode( ',', $arg );
		$category_ids = [];
		foreach ( $categories as $post_category ) {
			if ( trim( $post_category ) ) {
				if ( is_numeric( $post_category ) && (int) $post_category ) {
					$category_id = category_exists( (int) $post_category );
				} else {
					$category_id = category_exists( $post_category );
				}
				if ( ! $category_id ) {
					WP_CLI::error( "No such post category '{$post_category}'." );
				}
				$category_ids[] = $category_id;
			}
		}
		// If no category ids found, return exploded array for compat with previous WP-CLI versions.
		return $category_ids ?: $categories;
	}
48395
public function parse_args( $arguments ) {
		list( $positional_args, $mixed_args, $global_assoc, $local_assoc ) = self::extract_assoc( $arguments );
		list( $assoc_args, $runtime_config )                               = $this->unmix_assoc_args( $mixed_args, $global_assoc, $local_assoc );
		return array( $positional_args, $assoc_args, $runtime_config );
	}
999499
protected function handleValues(array $args)
    {
        if (\count($args) === 1) {
            $values = $args[0];
        } else {
            $values = [];

            foreach ($args as $i => $arg) {
                $values['Value ' . ($i + 1)] = $arg;
            }
        }

        return $values;
    }
964308
public function handleCategoryId($args)
    {
        $productId = $args['row']['product_id'];
        $categoryId = $args['row']['category_id'];

        if (!array_key_exists($productId, $this->categoryIds)) {
            $this->categoryIds[$productId] = [];
        }
        $this->categoryIds[$productId][] = $this->handleCategory($categoryId);
    }
870083
public function getEntities(array $args = [])
    {
        // @todo - use permission base to exclude secure if necessary.
        $replacementFilter = [
            'column' => 'f.object',
            'expr'   => 'neq',
            'value'  => ['company'],
        ];
        foreach ($args as $type => &$arg) {
            if ('filter' === $type) {
                foreach ($arg as $key => &$filter) {
                    if ('force' === $key) {
                        foreach ($filter as $forceKey => &$forceFilter) {
                            if (
                                !empty($forceFilter['column'])
                                && 'f.object' == $forceFilter['column']
                                && !empty($forceFilter['expr'])
                                && 'eq' == $forceFilter['expr']
                                && !empty($forceFilter['value'])
                                && 'lead' == $forceFilter['value']
                            ) {
                                $forceFilter = $replacementFilter;
                            }
                        }
                    } elseif ('object' === $key && 'lead' === $filter) {
                        // Move the filter to force mode in order to replace.
                        if (!isset($arg['force'])) {
                            $arg['force'] = [];
                        }
                        $arg['force'][] = $replacementFilter;
                        unset($arg[$key]);
                    }
                }
            }
        }

        return parent::getEntities($args);
    }
376971
public function createContent(array $args): array
    {
        $post = $this->getDriver()->content->create($args);

        return array(
            'id'   => (int) $post->ID,
            'slug' => $post->post_name,
            'url'  => $post->url,
        );
    }
747560
public function decode(array $args)
    {
        $decoded = [];

        foreach ($args as $arg) {

            if (!is_string($arg)) {
                $decoded[] = $arg;
                continue;
            }

            $decoded[] = $this->deserialize($arg);

        }

        return $decoded;
    }
1314902
public function parse_query_args( $args ) {
		$query_args = [
			'frontend' => $args,
			'backend'  => $args,
		];

		if ( isset( $args['frontend'] ) || isset( $args['backend'] ) ) {
			foreach ( [ 'frontend', 'backend' ] as $query_type ) {
				$query_args[ $query_type ] = isset( $args[ $query_type ] )
					? $args[ $query_type ]
					: [];
			}
		}

		return $query_args;
	}
114216
public function resolveMetaArguments($arguments)
    {
        if ($this->isPreservedAs('multiple') && ! isset($arguments['key'])) {
            throw new MetaArgumentsException("You need to provide key for processing Taxonomy [{$this->slug}] meta.");
        }

        return array_merge($this->metaDefaults, $arguments);
    }
470483
public function url( array $args = [] ) {
		$url = get_permalink( $this->ID );
		if ( $args ) {
			$url = add_query_arg( $args, $url );
		}

		return $url;

	}
1266501
protected function _splitArgs($args)
    {
        $out = [];
        foreach ($args as $arg) {
            if (strpos($arg, ':') !== false) {
                list($key, $value) = explode(':', $arg);
                if (in_array($value, ['true', 'false'])) {
                    $value = $value === 'true';
                }
                $out[$key] = $value;
            } else {
                $out[] = $arg;
            }
        }

        return $out;
    }
1262910
public function url( array $args = [] ) {
		$url = $this->siteurl;
		if ( $args ) {
			$url = add_query_arg( $args, $url );
		}

		return $url;
	}
1107363
protected function lib_e($arg)
    {
        switch ($arg[0]) {
            case 'list':
                $items = $arg[2];
                if (isset($items[0])) {
                    return $this->lib_e($items[0]);
                }

                return self::$defaultValue;
            case 'string':
                $arg[1] = '';

                return $arg;
            case 'keyword':
                return $arg;
            default:
                return array('keyword', $this->compileValue($arg));
        }
    }
639537
protected function parseArgument($arg)
    {
        $arg = ltrim($arg, '-');
        
        $key = $arg;
        $value = true;
        
        if (strpos($arg, '=') !== false) {
            $key = substr($arg, 0, strpos($arg, '='));
            $value = substr($arg, strpos($arg, '=') + 1);
        
            if (is_numeric($value)) {
                // Transform the value into the correct data type
                $value = $value * 1;
            }
        }
        
        return array($key, $value);
    }
1003116
public function attachments(...$args)
    {
        $attachables = $this->attachableObjects();
        $attachments = call_user_func_array([ $this, 'getAttachments' ], $args);

        foreach ($attachments as $attachment) {
            if (isset($attachables[$attachment->objType()])) {
                $attachment->attachmentType = $attachables[$attachment->objType()];
            } else {
                $attachment->attachmentType = [];
            }
        }

        return $attachments;
    }
528970
public function getEncodeArray(array $args) {
        $data = [];
        foreach ($args as $key => $item) {
            $data[] = sprintf('%s=%s', urlencode($key), urlencode($item));
        }
        return sprintf('{%s}', implode('&', $data));
    }
537469
private function getArguments($argsNumber, $arguments)
    {
        if ($argsNumber == 1 && is_string($arguments)) {
            return [$arguments];
        } elseif ($argsNumber === count($arguments)) {
            return $arguments;
        }

        for ($i = 0; $i < $argsNumber; $i++) {
            if (array_key_exists($i, $arguments)) {
                $args[] = $arguments[$i];
                continue;
            }

            return $args;
        }

        return [];
    }