Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpstan: Streamline vendor file location with local dev-env #5175

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:

- name: Setup dependencies
run: |
composer require -n --no-progress overtrue/phplint
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git vendor/icinga-php-library
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git vendor/icinga-php-thirdparty
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-x509.git vendor/modules/x509-web
git clone --depth 1 https://github.com/Icinga/icingadb-web.git vendor/modules/icingadb-web
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-pdfexport.git vendor/modules/pdfexport-web
composer require -n --no-progress overtrue/phplint phpstan/phpstan
sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git /usr/share/icinga-php/ipl
sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git /usr/share/icinga-php/vendor
sudo git clone --depth 1 https://github.com/Icinga/icingaweb2-module-x509.git /usr/share/icingaweb2-modules/x509
sudo git clone --depth 1 https://github.com/Icinga/icingadb-web.git /usr/share/icingaweb2-modules/icingadb
sudo git clone --depth 1 https://github.com/Icinga/icingaweb2-module-pdfexport.git /usr/share/icingaweb2-modules/pdfexport

- name: PHP Lint
if: ${{ ! cancelled() }}
Expand All @@ -50,7 +50,7 @@ jobs:

- name: PHPStan
if: ${{ ! cancelled() }}
uses: php-actions/phpstan@v3
run: ./vendor/bin/phpstan analyse

test:
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions library/Icinga/Cli/Documentation/CommentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CommentParser
protected $raw;
protected $plain;
protected $title;
/** @var array $paragraphs */
protected $paragraphs = array();

public function __construct($raw)
Expand Down Expand Up @@ -37,6 +38,7 @@ protected function parse()
$p = null;
foreach (preg_split('~\n~', $plain) as $line) {
// Strip * at line start
/** @var string $line */
$line = preg_replace('~^\s*\*\s?~', '', $line);
$line = rtrim($line);
if ($this->title === null) {
Expand Down
42 changes: 32 additions & 10 deletions library/Icinga/Protocol/Ldap/LdapConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class LdapConnection implements Selectable, Inspectable

/**
* The LDAP link identifier being used
*
* @var resource
*/
protected $ds;

Expand Down Expand Up @@ -248,7 +246,7 @@ public function root()
*
* Establishes a connection if necessary.
*
* @return resource
* @throws LdapException
*/
public function getConnection()
{
Expand Down Expand Up @@ -617,16 +615,22 @@ public function testCredentials($bindDn, $bindPw)
/**
* Return whether an entry identified by the given distinguished name exists
*
* @param string $dn
* @param string $dn
*
* @return bool
*
* @throws LdapException
*/
public function hasDn($dn)
{
$ds = $this->getConnection();
$this->bind();

$result = ldap_read($ds, $dn, '(objectClass=*)', array('objectClass'));
if ($result === false) {
return false;
}

return ldap_count_entries($ds, $result) > 0;
}

Expand Down Expand Up @@ -654,6 +658,10 @@ public function deleteRecursively($dn)
}

$children = ldap_get_entries($ds, $result);
if ($children === false) {
return false;
}

for ($i = 0; $i < $children['count']; $i++) {
$result = $this->deleteRecursively($children[$i]['dn']);
if (! $result) {
Expand Down Expand Up @@ -785,6 +793,10 @@ protected function runQuery(LdapQuery $query, array $fields = null)
$count = 0;
$entries = array();
$entry = ldap_first_entry($ds, $results);
if ($entry === false) {
return [];
}

do {
if ($unfoldAttribute) {
$rows = $this->cleanupAttributes(ldap_get_attributes($ds, $entry), $fields, $unfoldAttribute);
Expand Down Expand Up @@ -952,6 +964,10 @@ protected function runPagedQuery(LdapQuery $query, array $fields = null, $pageSi
}

$entry = ldap_first_entry($ds, $results);
if ($entry === false) {
return [];
}

do {
if ($unfoldAttribute) {
$rows = $this->cleanupAttributes(ldap_get_attributes($ds, $entry), $fields, $unfoldAttribute);
Expand Down Expand Up @@ -1184,9 +1200,7 @@ protected function encodeSortRules(array $sortRules)
/**
* Prepare and establish a connection with the LDAP server
*
* @param Inspection $info Optional inspection to fill with diagnostic info
*
* @return resource A LDAP link identifier
* @param ?Inspection $info Optional inspection to fill with diagnostic info
*
* @throws LdapException In case the connection is not possible
*/
Expand All @@ -1199,6 +1213,9 @@ protected function prepareNewConnection(Inspection $info = null)
$hostname = $this->normalizeHostname($this->hostname);

$ds = ldap_connect($hostname);
if ($ds === false) {
throw new LdapException('Failed to connect to LDAP');
}

// Set a proper timeout for each connection
ldap_set_option($ds, LDAP_OPT_NETWORK_TIMEOUT, $this->timeout);
Expand Down Expand Up @@ -1228,7 +1245,7 @@ protected function prepareNewConnection(Inspection $info = null)
}

/**
* Perform a LDAP search and return the result
* Perform a LDAP search and return the result or false on error
*
* @param LdapQuery $query
* @param array $attributes An array of the required attributes
Expand All @@ -1238,8 +1255,6 @@ protected function prepareNewConnection(Inspection $info = null)
* @param int $deref
* @param array $controls LDAP Controls to send with the request (Only supported with PHP v7.3+)
*
* @return resource|bool A search result identifier or false on error
*
* @throws LogicException If the LDAP query search scope is unsupported
*/
public function ldapSearch(
Expand Down Expand Up @@ -1553,6 +1568,13 @@ public function inspect()
return $insp;
}

/**
* Normalize all given hostnames to a valid LDAP URL
*
* @param string $hostname
*
* @return string
*/
protected function normalizeHostname($hostname)
{
$scheme = $this->encryption === static::LDAPS ? 'ldaps://' : 'ldap://';
Expand Down
Loading
Loading