Psalm not show attributes methods errors in another file - phpdoc

If I call the method \Test\MyClass::test('string'); in file 1. psalm work correct and show error "psalm: InvalidScalarArgument: Argument 1 of..."
Why in file 2 psalm dont show attributes errors?
File 1:
<?php
//file1.php
namespace Test;
class MyClass{
/**
* #psalm-param int $a
* #return void
*/
static function test(int $a){}
}
File 2:
//file2.php
\Test\MyClass::test('string');
psalm.xml:
<?xml version="1.0"?>
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xmlns:xi="http://www.w3.org/2001/XInclude"
errorLevel="1"
>
</psalm>

Related

Jenkins Job DSL trigger is deprecated

I am using the Job DSL Jenkins plugin, and I have got a problem regarding the trigger. It is deprecated and when I update the code, then the deprecation warning is still shown.
Here the code before:
protected def job
void nightly(String schedule='H 0 * * *') {
job.triggers {
cron(schedule)
}
}
Then the update according to: https://github.com/jenkinsci/job-dsl-plugin/wiki/Migration
void nightly(String schedule='H 0 * * *') {
properties {
pipelineTriggers {
job.triggers {
cron(schedule)
}
}
}
}
There is still a warning: Warning: (JobBuilder.groovy, line 100) triggers is deprecated
What am I doing wrong? Is the properties keyword wrong or should it be job.properties?
thanks in advance
job basically represents project block of a job XML configuration file and its methods are converted to nested XML elements.
Your initial code
void nightly(String schedule = 'H 0 * * *') {
job.triggers {
cron(schedule)
}
}
renders this part:
<triggers>
<hudson.triggers.TimerTrigger>
<spec>H 4 * * *</spec>
</hudson.triggers.TimerTrigger>
</triggers>
Your updated code does effectively the same thing, because you are calling triggers method of job exactly like before the update. Another problem is that cron method specification for pipelineTriggers is different, so the correct code is:
void nightly(String schedule = 'H 0 * * *') {
job.properties {
pipelineTriggers {
triggers {
cron {
spec(schedule)
}
}
}
}
}
You can view available Jenkins DSL methods at https://your.jenkins.domain/plugin/job-dsl/api-viewer/index.html

VSCode - Reference a type of a module from JS

Using Visual Studio Code for JS programming I can access some features from typescript; since the editor will parse all .d.ts files around, it'll help me with variable types. For example it does recognize the following:
any.js
/**
* #param {string} s
* #return {Promise<Person>}
*/
function foo(s){ ... }
foo('Jhon').then((p) => p.name )
index.d.ts
interface Person {
name: string
surname: string
}
Now, I want to access types (interfaces, classes... whatever) declared in node.d.ts declaration file; for example it declares the module stream which declares the Readable interface.
I'm looking for something like this:
const stream = require('stream')
/**
* #param {stream.Readable} stream
*/
function goo(stream) { ... }
But that does not work.I've tried with:
{internal.Readable}
{stream.Readable}
{Node.stream.Readable}
{Node.Readable}
{Node.internal.Readable}
As of VS Code 1.18, this is a limitation when using require with JSDoc types. I've opened this issue to track this specifically
Some possible workarounds:
Use import:
import * as stream from 'stream'
/**
* #param {stream.Readable} stream
*/
function goo(stream) { ... }
or import Readable explicitly:
const stream = require('stream')
const {Readable} = require('stream')
/**
* #param {Readable} stream
*/
function goo(stream) { ... }
https://github.com/Microsoft/TypeScript/issues/14377 also tracks allowing you to specify module imports in jsdocs directly.

Is the FileOutputFormat.setCompressOutput(job, true); optional?

In Hadoop program, I tried to compress the result, I wrote the following code:
FileOutputFormat.setCompressOutput(job, true);
FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
The result was compressed, and when I delete the first line:
FileOutputFormat.setCompressOutput(job, true);
and execute the program again, the result was same, was the above code
FileOutputFormat.setCompressOutput(job, true);
optional? What is the function of that code?
Please see the below methods in FileOutPutFormat.java which internally calls the method call which you have deleted.
i.e setCompressOutput(conf, true);
That means you are trying apply Gzip codec class then obviously its a pointer to code that output should be compressed. Isnt it ?
/**
* Set whether the output of the job is compressed.
* #param conf the {#link JobConf} to modify
* #param compress should the output of the job be compressed?
*/
public static void setCompressOutput(JobConf conf, boolean compress) {
conf.setBoolean("mapred.output.compress", compress);
}
/**
* Set the {#link CompressionCodec} to be used to compress job outputs.
* #param conf the {#link JobConf} to modify
* #param codecClass the {#link CompressionCodec} to be used to
* compress the job outputs
*/
public static void
setOutputCompressorClass(JobConf conf,
Class<? extends CompressionCodec> codecClass) {
setCompressOutput(conf, true);
conf.setClass("mapred.output.compression.codec", codecClass,
CompressionCodec.class);
}

Laravel Monolog Syslog specify individual log file?

I have Laravel setup so Monolog logs to syslog. Here is whats' in my start/global.php:
$monolog = Log::getMonolog();
$monolog->pushHandler(new Monolog\Handler\SyslogHandler('mywebsitename'));
This works well, except all log messages are dumped into /var/log/messages.
How can I specify a specific log file instead of messages? I've seen something called custom "channels" with Monolog. Is it something to do with that?
Also, how do I make sure that this log file is rotated like the rest of my log files?
I'm using Laravel 4.2, and in my setLog function I've added the RotatingFileHandler. This will solve both problems for you.
This code creates a file called mttParser-{Y-m-d}.log in app/storage/logs/import/, where {Y-m-d} is converted to todays date. The second parameter to the RotatingFileHandler, 10, sets to keep 10 versions of the log file before deleting them.
The IntrospectionProcessor simply adds the method, class, line number, where the log was called.
trait LogTrait
{
/**
* #var string The location within the storage path to put the log files
*/
protected $logFileLocation = 'logs/import/';
protected $logFileName = 'mttParser.log';
/**
* #var Logger
*/
protected $log;
/**
* Returns a valid log file, re-using an existing one if possible
*
* #return \Monolog\Logger
*/
public function getLog()
{
// Set a log file
if (!isset( $this->log )) {
$this->setLog();
}
// If it's been set somewhere else, re-create it
if ('Monolog\Logger' !== get_class( $this->log )) {
$this->setLog();
}
return $this->log;
}
/**
* Sets the log file
*/
public function setLog()
{
$this->log = new Logger( 'mttParserLog' );
// Make sure our directory exists
if (!File::isDirectory( storage_path( $this->logFileLocation ) )) {
File::makeDirectory( storage_path( $this->logFileLocation ) );
}
$this->log->pushHandler( new RotatingFileHandler( storage_path( $this->logFileLocation . $this->logFileName ),
10 ) );
$this->log->pushProcessor( new IntrospectionProcessor() );
}
}

Error with undefined method CI_Loader::plugin()

I received the following error:
Call to undefined method CI_Loader::plugin() in C:\wamp\www\Code\application\libraries\DX_Auth.php on line 1233
on this code:
function captcha()
{
$this->ci->load->helper('url');
$this->ci->load->plugin('dx_captcha');
$captcha_dir = trim($this->ci->config->item('DX_captcha_path'), './');
Make sure you have moved any array values in application/config/autoload.php from $autoload[‘plugins’] to $autoload[‘helpers’] or you will notice stuff break.
This is the reference
Which version of CI are you using? Plugins has been removed since the 2.x and replaced with helper.
Try to use reCaptcha instead, it has a good library.
You're trying to load a plugin and plugins are not supported, if I remember it right since CI version 2. If that's the case (which seems to be) you need to convert your plugins into helpers.
I think you are trying to use an old version of DX_Auth on new version of CodeIgniter. Current version of DX_Auth is compatible with CI 2.x and is available on github.
A simple way to solve this problem is that you just put this code in your loader.php. The plugin its works. Go to System->Core->Loader.php.
/**
* Load Plugin
*
* This function loads the specified plugin.
*
* #access public
* #param array
* #return void
*/
function plugin($plugins = array())
{
if ( ! is_array($plugins))
{
$plugins = array($plugins);
}
foreach ($plugins as $plugin)
{
$plugin = strtolower(str_replace(EXT, '', str_replace('_pi', '', $plugin)).'_pi');
if (isset($this->_ci_plugins[$plugin]))
{
continue;
}
if (file_exists(APPPATH.'plugins/'.$plugin.EXT))
{
include_once(APPPATH.'plugins/'.$plugin.EXT);
}
else
{
if (file_exists(BASEPATH.'plugins/'.$plugin.EXT))
{
include_once(BASEPATH.'plugins/'.$plugin.EXT);
}
else
{
show_error('Unable to load the requested file: plugins/'.$plugin.EXT);
}
}
$this->_ci_plugins[$plugin] = TRUE;
log_message('debug', 'Plugin loaded: '.$plugin);
}
}
// --------------------------------------------------------------------
/**
* Load Plugins
*
* This is simply an alias to the above function in case the
* user has written the plural form of this function.
*
* #access public
* #param array
* #return void
*/
function plugins($plugins = array())
{
$this->plugin($plugins);
}

Resources